PIC Microcontroller

PIC 18F6722 기본프로그램

EP 기술연구소 2010. 4. 5. 09:22

/*********************************************
 Project : 

 Version : 1.0
 Author  : kornan-Park ( kornanp@empas.com)
 Company : EU-Technology
 
 Chip type           : PIC18F6722 (64pin TQFP)
 Program type        : Application
 Clock frequency     : 10.000000 MHz
 Memory model        : 128 Kbytes(Flash)
 External SRAM size  : 3936 bytes(SRAM)
 Data Stack size     : 1024 bytes(EEPROM)
 
 Note:
 1. First drawing : 2010-03-31
 
*********************************************/
#include "C:\Demo\GlassMain\GlassMain.h"
#include <stdio.h>

#include "GlassMain_Sub.c"  // Glass Cleaner Robot Sub-program
#include "GlassMain_KeyChk.c" // Key check routine

/*==========================================
// Timer 0 overflow interrupt service routine
============================================*/
#ZERO_RAM
#int_RTCC
void  RTCC_isr(void)
{
 TMR0L = 231; // 1.0 mSec Interrupt
 
 mSec1Flag = 1;
 
}
/*==========================================
// Timer 1 overflow interrupt service routine
============================================*/
//Timer1 = 200uSec Timer
#int_TIMER1
void  TIMER1_isr(void)
{
// 200uSec Timer
 
}
/*==========================================
// Timer 2 overflow interrupt service routine
============================================*/
#int_TIMER2
void  TIMER2_isr(void)
{
 //TMR0 = 0x0F;
    //TMR0 = 0x0F; 1mSec timer interrupt
    //if(BuzOnFlag) BuzOut = ~BuzOut;
    //else BuzOut = 0;
    //mSec1Flag = 1;
}
/*==========================================
// ADC interrupt service routine
============================================*/
#int_AD
void  AD_isr(void)
{
 //ADC_Buffer[AD_Channel] += ADRESH;
 //if(AD_Channel == 1) ADC_CompFlag = 1;
}
/*==========================================================
// USART0 (LCD Module) Receiver interrupt service routine
============================================================*/
//===== USART0 Receiver interrupt service routine
#int_RDA
void  RDA_isr(void)
{

}
//===== USART0 Transmitter interrupt service routine
#int_TBE
void  TBE_isr(void)
{

}

/*==========================================================
 MAIN Routine
============================================================*/

void main()
{
 
 setup_adc_ports(ALL_ANALOG|VSS_VDD);
 setup_adc(ADC_CLOCK_DIV_4|ADC_TAD_MUL_0);
 set_tris_B(0xF0);  // High 4bit = input, Lower 4bit = output
 PORTB = 0x0F;
 //port_b_pullups(TRUE);
 set_tris_c(0x40);
 PORTC = 0;
 set_tris_G(0x00); // PORTC =  all output set
 
 setup_psp(PSP_DISABLED);
 setup_spi(SPI_SS_DISABLED);
 setup_spi2(SPI_SS_DISABLED);
 
 setup_wdt(WDT_OFF);

 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_bit);
 setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
 setup_timer_2(T2_DIV_BY_4,0,1);
 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
 setup_timer_4(T4_DISABLED,0,1);
 setup_comparator(NC_NC_NC_NC);
 setup_vref(FALSE);
 
 enable_interrupts(INT_RTCC);
 enable_interrupts(INT_TIMER1);
 //enable_interrupts(INT_TIMER2);
 enable_interrupts(INT_AD);
 enable_interrupts(INT_RDA);
 //enable_interrupts(INT_TBE);
 
 DataInitial();
 
 enable_interrupts(GLOBAL);
 setup_low_volt_detect(FALSE);
 //Setup_Oscillator parameter not selected from Intr Oscillator Config tab

 while(1){
  if(mSec1Flag){
   mSec1Flag = 0;

   TimerCheck();
   //if(BuzFlag) BuzTimeCtl();
   // Key common port out
   LED_Out0 = 1;
   LED_Out1 = 1;
   if(++Common >= 4) Common = 0;
   PORTB |= 0x0F;
   PORTB &= Com_data[Common];
   LED_Ctrol();
   KeyScan();   // key input check
   //ADC_Start();

  }
  //TestPin = ~TestPin;
  if(PowerFlag) TestPin = 0; // Test LED on
  else TestPin = 1;  
 }

}
//#end

 

GlassMain.h
0.0MB