📄 main.c
字号:
/******************************************************************
Module description:
Main function for all project
Author : Yu Lu
luyu1974@gmail.com
*****************************************************************/
#include "main.h"
extern void write_usb(unsigned int usbadr, char dta);
extern void send_all_gp2021_TXD3();
extern void process_host_data(void);
extern void DELAY_1MS();
void init_clk_mem(void)
{
ROMSIZ |= 0X80; // enable 1024-byte on chip XRAMs
PMR |= 0x01; // DME1:0 = 01 -> internal SRAM data memory 000-3ff
CKCON &= 0XF8; // clear wait state
CKCON |= 0X02; // wait state is 2
#if M4X == 1
/* the following code is to set the clock = 4*8Mhz */
write_usb(0x7e01, 5); // clock from usbn9603 = 48/(5+1) = 8 MHz
DELAY_1MS();
EXIF &= 0xfb; // RGMD = 0
PMR &= 0xef; // clear CTM first
PMR |= 0x08; // 4x/2x = 1, multiplied by 4 ; CTM = 1, enable clock multiplier
PMR |= 0x10; // set CTM
while(!(EXIF & 0x08))
{
; // wait EXIF.3 to become 1
}
PMR &= 0x3f; // cd0 cd1 = 0 0
// after the clock freq is 4*8 = 32MHz
#endif
}
void main(void)
{
init_clk_mem();
init_ser(BAUT_115200); // this is for 22.1184MHz only
#if XRAM_DBG ==1
init_xram();
#endif
EA = 1; // enable interrupt
EX0 = 1; // enable int0
ES0 = 1; // enable serial port int
rst_usb();
init_usb();
start_sending = 0;
event = 0;
ET0 = 0; // disable timer0 overflow int
LPT0 = 1; // timer0 has higher priority
init_timer();
status &= 0xbf;
while(1)
{
// if host send command to get data, collect data from GP2021 and send them , then clean the flag
if( (HOST_ASK_DATA_FLAG)&&(TIME_TO_SEND_HOST) )
{
send_all_gp2021_TXD3();
CLR_HOST_ASK_DATA_FLAG;
CLR_TIME_TO_SEND;
}
} // end of while(1)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -