📄 main.c
字号:
#define PIC_CLK 8000000 //change this to 3.6864, 4, 16 or 20MHz
#define MCU 877
#include <pic.h>
//#include <pic1687x.h>
//#include <conio.h>
//#include <stdlib.h>
//#include <stdio.h>
//#include <ctype.h>
#include "always.h"
#include "delay.h"
#include "main.h"
#include "serial.h"
#include "GPS.H"
//include C files
#include "delay.c"
#include "GPS.C"
#include "TRW24G.c"
#include "serial.c"
#define SW1 RB7
#define SW2 RE2
#define LED1 RA5
#define LED2 RA4
bit Mode,Sw1On,Sw2On;
//=========================================================================================
#if defined(_16F887) || defined(_16F877) || defined(_16F873) || defined(_16F874) || defined(_16C76)
__CONFIG( WDTDIS & HS & UNPROTECT & PWRTEN & BOREN & LVPDIS & WRTDIS & DEBUGDIS &
UNPROTECT);
#else
#error Must be compiled for 16F87x, MPLAB-ICD or 16C76
#endif
//=========================================================================================
//bank1 unsigned char RX_BUF[25];
const unsigned char HexToAsc_Table[]={
'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F'};
//=========================================================================================
//=========================================================================================
//=========================================================================================
/* interrupt service routine*/
//-----------------------------------------------------------------------------------------
void interrupt isr(void)
{
unsigned char c;
if(RCIF)
{
c=RCREG;
if(OERR == 0 ) // 无溢出错误
{
GPS_Decode(c);
}
else
{
CREN = 0;
asm("nop");
CREN = 1;
}
}
else if(TMR1IF)
{
TMR1IF=0;
ReportTime++;
if(!SW1)
Sw1On=1;
else
{
if(Sw1On)
{
Mode=1;
LED1=1;
LED2=0;
Sw1On=0;
}
}
if(!SW2)
Sw2On=1;
else
{
if(Sw2On)
{
Mode=0;
LED1=0;
LED2=1;
Sw2On=0;
}
}
//ADON=1;
KeyStatus=PORTB&0x7c;
if(Mode)
KeyStatus |= 0x80;
}
else if(ADIF)
{
ADIF =0;
VR_Value=ADRESH;
ADGO=1;
}
}
//-----------------------------------------------------------------------------------------
/* interrupt service routine*/
//=========================================================================================
//=========================================================================================
//void initial(void)
//-----------------------------------------------------------------------------------------
void mcu_initial(void)
{
RP0=1; //choose bank 1
GIE=0; //disable all interrupt
OPTION=0x3f; //Prescaler select1:128 and assigned to WDT
INTCON=0; //GIE and PEIE disable;TO and INT enable;IntFlag cleared
PIE1=0; //TMER2中断,异步串行接收中断
PIR1=0;
PIR2=0;
//Set Port
ANSELH=0; //PORTB = I/O
PORTA = 0xcf;
PORTB = 0xff;
PORTC = 0xb0;
PORTD = 0xff;
PORTE = 0xfe;
TRISA = 0xcf; //
TRISB = 0xff; //PORTB.all input
TRISC = 0xb0; //
TRISD = 0xff; //RD all output
TRISE = 0xfe; //RE all output
//
T1CON= 0x1;
// TMR1IE=1; //enable TIME1 interrupt
//INIT_AD:
ADCON1=0x09; //ADFM=0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -