PIC Microcontroller

PIC16F877A 기본 프로그램

EP 기술연구소 2007. 11. 4. 20:09

/*******************************************************************************
  Project : Water Press Meter Controller
  Version : 1.0 (PressMeter.c)
  Date    : 2007. 09. 06
  Author  : JW Park(kornanp@emaps.com)
  Company : EU-Technology(Electronic Utopia Technology)
  
  Chip type           : PIC16F877A (44-pin TQFP)
  Program type        : CCS-C Compiler(C51.exe)
  Clock frequency     : 4.0MHz Crystal Oscillator
  Memory model        : 8K x 14 words of Flash Program Memory,
       : 256 x 8 bytes of EEPROM Data Memory
       : 368 x 8 bytes of Data Memory (RAM)
 ==========================================================================
  Note :
   1.

*******************************************************************************/
//=============================================================================
#include "C:\Demo\PressMeter\PressMeter.h"
#include <2402.C>
#ZERO_RAM

#include "PMeter_sub.c"
#include "LCD_DriverCtl.c"
#include "ADC_control.c"
#include "KeyControl.c"
#include "ADC_MCP3201_Ctl.c"

//=============================================================================
#int_RTCC
RTCC_isr()
{
 if(--mSec1Counter <= 0){
  mSec1Counter = 4;
  mSec1Flag = 1;
 }
}

#int_TBE
TBE_isr()
{

}

#int_RDA
RDA_isr()
{

}

#int_TIMER1
TIMER1_isr()
{

}

//=============================================================================

void main()
{

 PORT_IO_Init();  // Port Initial
 Timer_Init();
 
 setup_adc_ports(NO_ANALOGS);
 setup_adc(ADC_OFF);
 setup_psp(PSP_DISABLED);
 setup_spi(FALSE);
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
 setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
 setup_timer_2(T2_DISABLED,0,1);
 setup_comparator(NC_NC_NC_NC);
 setup_vref(FALSE);
 //init_ext_eeprom();
 
 enable_interrupts(INT_RTCC);
 //enable_interrupts(INT_TBE);
 //enable_interrupts(INT_RDA);
 enable_interrupts(INT_TIMER1);
 
 LCD_Command(Ext32K_On);
 LCD_Command(LCD_OnComm);
 LCD_Command(SYS_Enable);
 
 enable_interrupts(GLOBAL);
  
 while(1){
  // program to hear
  if(mSec1Flag){
   mSec1Flag = 0;
   TimerCheck();   // Time check sub-routine
   KeyScan();    // Key check Routine
   ReadADC_MCP3201();  // ADC (MCP3201) chip data read
   TestPin = ~TestPin;
  }
  
  if(mSec250Flag){
   mSec250Flag = 0;
   LCD_DataSet();  // LCD on/off control data set to LCD-Buffer
   LCD_Display();  // LCD data display
   LCD_DataRead();
   
  }
  RelayControl();
  
  //=========
 }

}