📄 main.c
字号:
#include "app_config.h"
void delay_1ms(unsigned int n);
volatile unsigned char time_1ms_cnt;
unsigned char time_1ms_flag;
volatile unsigned char time_10ms_cnt;
unsigned char time_10ms_flag;
volatile unsigned char time_100ms_cnt;
unsigned char time_100ms_flag;
volatile unsigned char time_500ms_cnt;
unsigned char time_500ms_flag;
__irq void T0_IRQHandler (void) //use timer0 as system timer tick
{
time_1ms_cnt++;
time_1ms_flag = 1;
if (time_1ms_cnt >= 10)
{
time_1ms_cnt = 0;
time_10ms_cnt++;
time_10ms_flag = 1;
if (time_10ms_cnt >= 10)
{
time_10ms_cnt = 0;
time_100ms_cnt++;
time_100ms_flag = 1;
if (time_100ms_cnt >= 5)
{
time_100ms_cnt = 0;
time_500ms_cnt++;
time_500ms_flag = 1;
}
}
}
T0IR = 1; //Clear interrupt flag
VICVectAddr = 0; //Acknowledge Interrupt
}
void timer_task(void)
{
if (time_1ms_flag)
{
AppTask1ms();
time_1ms_flag = 0;
}
if (time_10ms_flag)
{
AppTask10ms();
time_10ms_flag = 0;
}
if (time_100ms_flag)
{
AppTask100ms();
time_100ms_flag = 0;
}
if (time_500ms_flag)
{
AppTask500ms();
time_500ms_flag = 0;
}
}
void timer_init(void)
{
//Enable and setup timer interrupt, start timer
T0MR0 = 17142; /* 1msec = 17142 at 17.143 MHz */
T0MCR = 3; /* Interrupt and Reset on MR0 */
T0TCR = 1; /* Timer0 Enable */
VICVectAddr4 = (unsigned long)T0_IRQHandler;/* Set Interrupt Vector */
VICVectCntl4 = 15; /* use it for Timer0 Interrupt */
VICIntEnable |= (1 << 4); /* Enable Timer0 Interrupt */
}
void emc_init(void)
{
int x;
EMC_CTRL = 0x00000001; //use normal CS0
PCONP |= 0x00000800;
PINSEL6 = 0x00005555;
PINSEL8 = 0x00400000;//PINSEL8 = 0x55555555; only A11 is used as address pin
x = PINSEL9;
x &= 0x0FF0FFFF;
PINSEL9 = x | 0x50090000; //Seems that WE pin is a mistake of NXP, it's removed in datasheet rev .03.01
}
void io_init(void)
{
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 = 0;
PINSEL3 = 0;
PINSEL4 = 0;
PINSEL5 = 0;
PINSEL6 = 0;
PINSEL7 = 0;
PINSEL8 = 0;
PINSEL9 = 0;
PINSEL10 = 0;
PINSEL0 |= 0x0000000F; //SDA1 SCL1
PINSEL0 |= 0x000A8000; //MISO1 MOSI1 SCLK1
PINSEL0 |= 0x80000000; //SCLK0
PINSEL1 |= 0x00000028; //MISO0 MOSI0
PINSEL0 |= 0x00000050; //TXD0, RXD0
SCS |= 0x00000001; //enable FIO0 and FIO1
Orb(MD2_CS_DPRT,MD2_CS_PIN);
Orb(TC_CS_DPRT,TC_CS_PIN);
Orb(LCD_RST_DPRT,LCD_RST_PIN);
Orb(BL_CTL_DPRT,BL_CTL_PIN);
Orb(LED1_DPRT,LED1_PIN);
Orb(LED2_DPRT,LED2_PIN);
Orb(LED3_DPRT,LED3_PIN);
Orb(U1UP_DPRT,U1UP_PIN);
emc_init();
}
void main_init(void)
{
timer_init();
io_init();
}
void delay_1ms(unsigned int n)
{
unsigned char x;
while (n)
{
x = time_1ms_cnt;
while (x == time_1ms_cnt);
n--;
}
}
int main(void)
{
main_init();
delay_1ms(100);
AppInit();
while (1)
{
AppRun();
timer_task();
listen();
say();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -