/********************************************************************************
Project : Serial Load Board Controller
Version : 1.0
Date : 2010-06-13
Author : J.W. Park ( kornanp@shinbiro.com)
Company : Epianics Enterprise
Chip type : PIC16F887 (44 pin QFP-type)
Program type : CCS-C Compiler
Clock frequency : Internal Oscillator (8.0 MHz)
Memory model : Small
External SRAM size : 0
Data Stack size : 256
Comments:
1. First Drawing : 2008. 09. 28
*********************************************************************************/
#include "C:\Demo\SerialLoad\SerialLoad.h"
#include <stdio.h>
#ZERO_RAM
#include "SerialLoad_Sub.c" // Serial Load Sun-Routine
#include "SerialCtl_F887.c" // Serial Communication Routine
#include "ADC_control.c" // A/D Control Routine
/*==========================================
Timer0 interrupt service routine
============================================*/
#int_RTCC
void RTCC_isr(void)
{
// 1mSec Timer
mSec1Flag = 1;
}
/*==========================================
A/D Converter interrupt service routine
============================================*/
#int_AD
void AD_isr(void)
{
AD_Buffer[AD_Channel] += ADRESH;
if(AD_Channel == (AD_CONVERTER_SIZE-1)) AD_CompFlag = 1;
}
/*==========================================
USART Transmitter interrupt service routine
============================================*/
#int_TBE
void TBE_isr(void)
{
if(++Tx_Counter <= TX_BUFFER_SIZE){
TXREG = TX_Buffer[Tx_Counter];
TXSTA |= TX_ENABLE; // Tx Interrupt Enable
}
else{
TX_buffer_overflow = 1;
TXSTA &= ~TX_ENABLE; // Tx Interrupt Disable
}
}
#int_RDA
void RDA_isr(void)
{
unsigned char status, data;
status = RCSTA;
data = RCREG;
if ((status & (FRAMING_ERROR | OVERRUN_ERROR))==0){
if((RX_counter >= RX_BUFFER_SIZE) & (data == 0x2A)) RX_counter = 0;
RX_Buffer[RX_counter] = data;
if(++RX_counter == RX_BUFFER_SIZE) RX_buffer_overflow = 1;
TestPin = ~TestPin;
}
}
/*==========================================
Timer1 interrupt service routine
============================================*/
#int_TIMER1
void TIMER1_isr(void)
{
}
/*==========================================
Timer2 interrupt service routine
============================================*/
#int_TIMER2
void TIMER2_isr(void)
{
}
/*==========================================
Main Routine
============================================*/
void main()
{
PORTA = 0;
set_tris_a(0b00101111); // 1 = input, 0 = output
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_8);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
setup_timer_2(T2_DIV_BY_16,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_RTCC);
enable_interrupts(INT_AD);
enable_interrupts(INT_TBE);
enable_interrupts(INT_RDA);
//enable_interrupts(INT_TIMER1);
//enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ);
while(true){
if(mSec1Flag){
TimerCheck();
ADC_Start(); // A/D converter Start
}
// 3. A/D Converter Control
if(AD_CompFlag) AD_Converter(); // A/D Converter Complete
// 4. USART(Serial) Control
if(RX_buffer_overflow) RX_Complete(); // Rx Complete Routine
if(USART_SendFlag & TX_buffer_overflow) TX_Start(); // Serial Tx control
//TestPin = ~TestPin;
}
}
'PIC Microcontroller' 카테고리의 다른 글
MPLAB IDE ( Target 보드 구성시 주의 사항 ) (0) | 2010.08.12 |
---|---|
16F723 기본 프로그램 (0) | 2010.06.28 |
Tilt Sensor (ADXL203, 2-Axis, AnalogDivices社) Example Program (0) | 2010.05.26 |
Summary of CCS C compiler Access to PIC internal peripherals (0) | 2010.05.14 |
PIC Microchips ORCAD Library (0) | 2010.05.13 |