⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 PIC18F4520 + TW8806B ucosII+net test program source
💻 C
字号:
//==============================================================================================
//    Project		: AD Board
//    Processor		: PIC18F252
//    Software Design	: Kim Yong Jun
//    Update		: 2007. 09. 18.
//    Compiler		: HI-TECH PICC-18 Compiler
//===============================================================================================

//==============	⒀ Main Include File ⑿  ===========================================================*/
#include	"PIC18F4520.h"
#include	"Main.h"		//Main Include Files
#include	"PIC Library.h"	//PIC Library include
#include	"I2C.h"		//PIC I2C Control Routine
#include	"Tuch.h"		//Tuch Screen Control Routine

/*==============	⒀ CPU Config Option ⑿  ==========================================================*/
//__CONFIG(1,0xC800);	//Intenal Oscillator Select, Fail-Safe Clock Monitor Enable, Oscillator Switchover Mode Enable
__CONFIG(1,0xC100);	//XT Oscillator Select, Fail-Safe Clock Monitor Enable, Oscillator Switchover Mode Enable
__CONFIG(2,0x0A16);	//Watchdog ±32 Disable, Power-Up Timer Enable, BOR Enable and SBOREN Disalbe, BOR 2.7V
__CONFIG(3,0x8100);	//MCLR Pin Enable, Timer1 Higher Power Operation, PORTB<4:0> Pins Digital I/O ON Reset, CCP2 = RC1
__CONFIG(4,0x0081);	//RB6,RB7 = I/O Port Select, Low Power Program Disable, Stack Full Reset Enable
__CONFIG(5,0xC00F);	//Code Protection, EEPROM Code, Boot Block Code All Disable
__CONFIG(6,0xE00F);	//EEPROM and Config Write Protection, Write Protection All Disable
__CONFIG(7,0x400F);	//Boot Table Read and  Boot Table Read Protection Disable
/*==============================================================================================*/

/*==============	⒀ System Main Control Routine ⑿  ==================================================*/
void main(void)
{
	Clear_Watchdog;		//Watchdog 600ms Time Out Clear at the Fosc = 4MHz
	WDTCON	= ON;		//Watchdog Enable
	INTCON	= 0B00000000;	//Global Interrupt All Disable
//	OSCCON	= 0B01100010;	//Internal Oscillator 4Mhz Select and SLEEP Mode Enable
	OSCCON	= 0B01100000;	//External Oscillator Select and SLEEP Mode Enable
	INTCON2	= 0B10000100;	//PORT Pull-up Disable, Timer0 = High Priority Interrupt Bit.2
	INTCON3 	= 0B00000000;	//INT1,2 Low Priority Interrupt and Disable
	PIE1	= 0B00000000;	//Peripheral Interrupt 1 All Disable
	PIE2	= 0B00000000;	//Peripheral Interrupt 2 All Disable
	IPR1	= 0B00000000;	//Peripheral1 Interrupt Low Priority Interrupt
	IPR2	= 0B00000000;	//Peripheral2 Interrupt Low Priority Interrupt
	RCON	= 0B10000000;	//Enable Priority Levels On Interrupts Bit.7
	CMCON	= 0B00000111;	//Comparator OFF
	CVRCON	= 0B00000000;	//Comparator Voltage Reference OFF
	ADCON2	= 0B00100011;	//Left justified, FRC Clock, 20TAD Mode
//	ADCON1	= 0B00001100;	//AN0 ~ AN2 Select
//	ADCON0	= 0B00001001;	//AN2 Channel ADC Mudule Enable
	ADCON1	= 0B00001111;	//All Digital IO Port
	ADCON0	= 0B00001000;	//AN2 Channel ADC Mudule Disable
	PORTA	= 0B00000000;	//Port_A Output Initialize
	TRISA	= 0B11110100;	//Configures port A(1 = Input, 0 = Output)
	PORTB	= 0B00000000;	//Port_B Output Initialize
	TRISB	= 0B11110001;	//Configures port B(1 = Input, 0 = Output)
	PORTC	= 0B00000000;	//Port_C Output Initialize
	TRISC	= 0B10011111;	//Configures port C(1 = Input, 0 = Output)
	PORTD	= 0B00000000;	//Port_D Output Initialize
	TRISD	= 0B11110111;	//Configures port D(1 = Input, 0 = Output)
	PORTE	= 0B00000000;	//Port_E Output Initialize
	TRISE	= 0B00000001;	//Configures port E(1 = Input, 0 = Output)
	
	delay_ms(10);
	TW88_SLEEP = OFF;
	delay_ms(100);
	TW88_RST = ON;

	I2C_Initialize();			//I2C Initialize
	MXB7843_Initialize();
	TIMER0_Enable();			//Timer 0 Enable
	INTCON |= 0xC0;			//Global and Peripheral Interrupt Enable

	for(;;){	Clear_Watchdog;		//Watchdog Enable and 600ms Time Out Clear
		
	}//End of While Routine
}//End of Main Routine

/*==============	⒀ PICC-18 High Priority Interrupt Routine ⑿  ==========================================*/
void interrupt HI_ISR(void)
{
	/*==============	⒀ Timer 0 Interrupt Routine ⑿  ==============*/
	if((TMR0IE)&&(TMR0IF)&&(TMR0IP)){
		TMR0H = 0x3C;		//100ms Timer Reload
		TMR0L = 0xAF;		//100ms Timer Reload
		TMR0IF = OFF;		//Timer0 Interrupt Fleg Clear
		
		RLED ^= ON;
		OSD_LED ^= ON;
	}//End of TIMER0_Interrupt
	
	return;
}//End of interrupt HI_ISR

/*==============	⒀ PICC-18 Low Priority Interrupt Routine ⑿  ==========================================*/
void interrupt low_priority LOW_ISR(void)
{
	/*============== ⒀ Timer 1 Interrupt Routine ⑿===============*/
	if((TMR1IE)&&(TMR1IF)&&(!TMR1IP)){
		TMR1H = 0x3C;		//100ms Timer Reload
		TMR1L = 0xAF;		//100ms Timer Reload
		TMR1IF = OFF;		//Timer1 Interrupt Fleg Clear

	}//End of TIMER1_Interrupt
	
	return;
}//End of interrupt LOW_ISR Routine
/*=============================================================================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -