📄 util.c
字号:
/* YuanGao electronic designe co.ldt
(c) Copyright 2002,2003, All Rights Reserved */
#include <w77e58.h>
#include "global.h"
#include "io.h"
#include "util.h"
//#define UART0_9600_11M
#define UART0_19200_11M
//#define UART0_38400_11M
//uchar idata SysTask;
uchar idata SysTimer;
uchar idata Uart0Timer;
UINT16 idata GPSTimer30;
uchar idata _timer0=0; /* timer0 interrupt counter, use this counter to adjust timeout counters period */
#define TIMEOUT_FACTOR 17 /* timeout factor x 1.0ms (timer0 period) = actual timeout period */
//P3.2 0003H INT0
void ISR_INT0(void) interrupt 0 //using 1
{
;
}
//Timer0 000BH
void ISR_Timer0(void) interrupt 1 //using 2
{
//TIMER0: Mode 1每中断一次的时间间隔是:Timer=T x (2^16-TH0TL0),T=(12/11.0592)/4; 0XF760的定时是:0.27126736 X (65536-63328)=0.27126736X2208=599u
//TIMEOUT_FACTOR=17的定时为:17x599us =10183 us =10(ms)
TF0 = 0;
TH0 = 0xF7;
TL0 = 0x60;
TR0 = 1;
/* count down timeout counters */
if( _timer0 < TIMEOUT_FACTOR )
_timer0++;
else
{
_timer0 = 0;
if(SysTimer) SysTimer--;
if(Uart0Timer) Uart0Timer--;
if(GPSTimer30) GPSTimer30--;
}
}
//P3.3 Int1 0013H
void ISR_INT1(void) interrupt 2 //using 1
{
;
}
/**************************************************************************
* Timer1 for 1.5ms interrupt
**************************************************************************/
//Timer1 001bH
void ISR_Timer1(void) interrupt 3 //using 1
{
#if 0
TH1 = 0xf7; /* 0xf7 */
TL1 = 0; /* 0x0 */
TR1 = 1;
/* count down timeout counters */
if( _timer0 < TIMEOUT_FACTOR )
_timer0++;
else
{
_timer0 = 0;
if(SysTimer) SysTimer--;
}
#endif
}
#if 0
//*****************************************
//串口中断处理
//serial_0 0023H
void serial(void) interrupt 4 //using 2
{
if (TI)
{
TI = 0;
//SBUF='1';
#if 1
if (outbufsign)
//if (putlast==outlast) outbufsign=0;
//else
{
SBUF=*outlast; //未发送完继续发送
outlast++; //最后传出去的字节位置加一
if (outlast==outbuf+OLEN) outlast=outbuf;//地址到顶部回到底部
if (putlast==outlast) outbufsign=0; //数据发送完置发送缓冲区空标志
}
else outbufsign0=0;
#endif
}
if (RI)
{
#if 0
RI = 0;
if(!inbufful)
{
*inlast= SBUF; //放入数据
inlast++; //最后放入的位置加一
inbufsign=1;
if (inlast==inbuf+ILEN) inlast=inbuf; //地址到顶部回到底部
if (inlast==getlast) inbufful=1; //接收缓冲区满置满标志
}
#endif
}
}
#endif
/**************************************************************************
* Timer2 for 2ms interrupt
**************************************************************************/
//002BH
void ISR_Timer2(void) interrupt 5 //using 1
{
;
}
#if 0
//SERIAL 1 003BH
void serial_1(void) interrupt 7 //using 2
{
if(RI_1)
{
RI_1 = 0;
}
if(TI_1)
{
TI_1=0;
SBUF1=0x34;
#if 0
while(TI_1_1==0) ;
TI_1=0;
SBUF1=0x35;
while(TI_1_1==0) ;
TI_1=0;
SBUF1=0x36;
while(TI_1_1==0) ;
TI_1=0;
#endif
}
}
#endif
//P1.4
void ISR_Int2(void) interrupt 8 //using 1
{
//if(SysTask==0)SysTask++;
}
void ISR_Int3(void) interrupt 9 //using 1
{
;
}
void ISR_Int4(void) interrupt 10 //using 1
{
;
}
void ISR_Int5(void) interrupt 11 //using 1
{
;
}
void ISR_WatchDog(void) interrupt 12 //using 1
{
;
}
#ifdef DEBUG_GPS
#define UART1_9600_11M
#else
#define UART1_4800_11M
#endif
/**************************************************************************
* Init system
**************************************************************************/
void CPU_init(void)
{
EA = 0;
EIE = 0;
P1=0xff;
P3=0xff;
P0=0xff;
//system init ,其中串口0用定时器2,串口1用定时器1
//串口1的设置
IE = 0x90; //允许总中断和串口0的中断
TMOD=0x20; //定时器1工作在模式2
//CKCON=0x30; //Timerl和Timer2时钟为1/12CLOCK
//CKCON |= 0x10; //Timer1 =1/4 clock
//CKCON |= 0x20; //Timer2 =1/4 clock
#if 0
TL1=?; //baud rate=1200 /11.0592
TH1=?;
#endif
#if 0
TL1=244; //baud rate=2400 /11.0592
TH1=244;
#endif
#ifdef UART1_4800_11M //def BAUD_4800_11M
TL1=250; //0xfa 0xfa is baud rate=4800 /11.0592
TH1=250;
#endif
#ifdef UART1_9600_11M
TL1=253; //0XFDFD baud rate=9600 /11.0592
TH1=253;
#endif
SCON1=0x58; //工作在模式1,允许接收
//SCON1=0x50; /* mode 1: 8-bit UART, enable receiver */
//SMOD_1 = 1; //UART1 baud*2
ES1=1; //串口1中断允许
SCON=0x58; //工作在模式1,接收允许;
//SCON=0x50; /* mode 1: 8-bit UART, enable receiver */
PCON = 0x00; // SM0=0 SM1=1 在10位异步收发模式 SMOD=0 溢出速率/32
//PCON = 0x80; //UART0 baud*2
//定时器2:波特率=振荡器频率/(32*(65536-(RCAP2H,RCAP2L)))
//9600=11059200/(32X(65536-RCAP2HL))
T2CON=0x30; //用定时器2做串口0的波特率发生器
#if 0
RCAP2H=0xfe; // 11.0592M晶振下, baud rate=1200
RCAP2L=0xe0;
#endif
#if 0
RCAP2H=0xff; // 11.0592M晶振下, baud rate=2400
RCAP2L=0x70;
#endif
#ifdef UART0_4800_11M
RCAP2H=0xff; // 11.0592M晶振下, baud rate=4800
RCAP2L=0xb8;
#endif
#ifdef UART0_9600_11M
RCAP2H=0xff; // 11.0592M晶振下, baud rate=9600
RCAP2L=0xdc;
#endif
#ifdef UART0_19200_11M
RCAP2H=0xff; // 11.0592M晶振下, baud rate=19200 ?
RCAP2L=0xee;
#endif
#ifdef UART0_38400_11M
RCAP2H=0xff; // 11.0592M晶振下, baud rate=38400 ?
RCAP2L=0xf7;
#endif
TMOD |=0x01; //th1 auto load 2X8,th0 1X16
ET0 = 1;
TH0 = 0xf7;
TL0 = 0x60;
TR0 = 1;
TR2 = 1;
TR1 = 1;
}/*end CPU_system_init*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -