?? cpu.c
字號:
/********************************************************************************/
/* filename : CPU.h */
/* created : xillinx */
/* descript : 選擇CPU的類型 */
/********************************************************************************/
#include "../CPU/CPU.h"
#include "../CFG/CFG.h"
#include "../UART/UART.h"
extern unsigned int system_timer;
unsigned char data CPU_soft_timer_lo=0x0;
unsigned char data CPU_soft_timer_hi=0x0;
/********************************************************************************/
/* 地址定義表,由7412138譯碼,最高位必須為1<G引腳>,其余3位組合 */
/* +-----+-----+-----+-----+ */
/* | A15 | A14 | A13 | A12 | */
/* +-----+-----+-----+-----+ */
/* | 1 | 0 | 0 | 0 | 0x8000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 0 | 0 | 1 | 0x9000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 0 | 1 | 0 | 0xA000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 0 | 1 | 1 | 0xB000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 1 | 0 | 0 | 0xC000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 1 | 0 | 1 | 0xD000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 1 | 1 | 0 | 0xE000 */
/* +-----+-----+-----+-----+ */
/* | 1 | 1 | 1 | 1 | 0xF000 */
/* +-----+-----+-----+-----+ */
/********************************************************************************/
unsigned char volatile xdata c51_hc138_cs1[0x1000] _at_ 0x8000;
unsigned char volatile xdata c51_hc138_cs2[0x1000] _at_ 0x9000;
unsigned char volatile xdata c51_hc138_cs_io2[0x1000] _at_ 0xA000;
unsigned char volatile xdata c51_hc138_cs_lcd1[0x1000] _at_ 0xB000;
unsigned char volatile xdata c51_hc138_cs_lcd2[0x1000] _at_ 0xC000;
unsigned char volatile xdata c51_hc138_cs_keyr[0x1000] _at_ 0xD000;
unsigned char volatile xdata c51_hc138_cs_keyw[0x1000] _at_ 0xE000;
unsigned char volatile xdata c51_hc138_cs_mt[0x1000] _at_ 0xF000;
unsigned char volatile c51_U07_latch; //* U7數據寄存器
unsigned char volatile c51_U19_latch; //* CS-IO2寄存器
cpu_interrupt_function CPU_001_tick_process;
cpu_interrupt_function CPU_002_tick_process;
cpu_interrupt_function CPU_004_tick_process;
cpu_interrupt_function CPU_008_tick_process;
cpu_interrupt_function CPU_010_tick_process;
cpu_interrupt_function CPU_020_tick_process;
cpu_interrupt_function CPU_040_tick_process;
cpu_interrupt_function CPU_080_tick_process;
cpu_interrupt_function CPU_100_tick_process;
cpu_interrupt_function CPU_200_tick_process;
cpu_interrupt_function CPU_400_tick_process;
cpu_interrupt_function CPU_extern_0_process;
cpu_interrupt_function CPU_extern_1_process;
cpu_interrupt_function CPU_timer_02_process;
/********************************************************************************/
/* fun_name : CPU_interrupt_proc_null() */
/* version : v1.00 */
/* created : xillinx */
/* 這個函數是中斷的缺省函數,什么也不做 */
/********************************************************************************/
void CPU_interrupt_proc_null(void)
{ ;
}
/********************************************************************************/
/* system interrupt dispatch */
/* <0> <0003> INT_Extern_0 <==> HT9302D Recv dial number CLK INT */
/* <1> <000B> INT_Timer_0 <==> For system time */
/* <2> <0013> INT_Extern_1 <==> USB interrupt */
/* <3> <001B> INT_Timer_1 <==> Not used */
/* <4> <0023> INT_Serial <==> Sery interrupt */
/* <5> <002B> INT_Timer_2 <==> Not used */
/* <6> <0033> INT_Extern_2 <==> For codec chip read and write interrupt */
/* <7> <003B> INT_Extern_3 <==> Not used */
/********************************************************************************/
/********************************************************************************/
/* fun_name : CPU_uart_serial_initial() */
/* descript : 2'(SMOD) X Fosc */
/* load_val = 256 - ----------------- */
/* baud X 32 X 12 */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_uart_serial_initial(void)
{ PCON = 0x80; //* double baud
SCON = 0x50; //* SCON: mode 1, 8-bit UART, enable RECV
TMOD &= 0x0F;
TMOD |= 0x20; //* TMOD: timer 1, mode 2, 8-bit reload
TH1 = 0xFE; //* TH1: reload value for 115200 baud @ 44.2368MHz(22.1184Mx2)
TR1 = 1; //* TR1: timer 1 run
}
/********************************************************************************/
/* fun_name : CPU_timer_0_load_init_value() */
/* version : v1.00 */
/* created : xillinx */
/* descript : load value<==>65536-(oscxtime(s))/12=65536-44236800 x 0.002/12 */
/* 2MS定時器 */
/********************************************************************************/
void CPU_timer_0_load_init_value(void)
{ TR0=0x00;
TH0=0xE3;
TL0=0x34;
TR0=0x01;
}
/********************************************************************************/
/* fun_name : CPU_timer_0_initialize() */
/* version : v1.00 */
/* created : xillinx */
/* descript : clled by main intilize */
/********************************************************************************/
void CPU_timer_0_initialize(void)
{ TMOD &= 0xF0; //* TMOD: timer 0, mode 1, 16-bit
TMOD |= 0x01; //* counter Fosc/12
CPU_timer_0_load_init_value(); //* TR0: timer 0 run
}
/********************************************************************************/
/* fun_name : CPU_timer_0_interrupt() */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_timer_0_interrupt(void) interrupt 1
{ CPU_timer_0_load_init_value(); //* TR0: timer 0 run
CPU_timer_interrupt();
}
/********************************************************************************/
/* fun_name : CPU_timer_2_initialize() */
/* version : v1.00 */
/* created : xillinx */
/* descript : 定時器2初始化,用作紅外部分接收 */
/* T=12/OSC=12/44236800=0.01736
/********************************************************************************/
void CPU_timer_2_initialize(void)
{ C_T2 =0x00; //* 內部定時器
T2MOD &=0xFE; //* DCEN=0x0,遞增計數器,遞增計數到0xFFFF后,溢出,然后在把RCAP2L和RCAP2H加載到TL2和TH2
RCAP2L =0x00; //* 如果溢出了,就重新從0開始遞增計數
RCAP2H =0x00;
TL2 =0x00;
TH2 =0x00;
TR2 =0x00;
}
/********************************************************************************/
/* fun_name : CPU_extern_0_interrupt() */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_extern_0_interrupt(void) interrupt 0
{ CPU_extern_0_process();
}
/********************************************************************************/
/* fun_name : CPU_extern_1_interrupt() */
/* descript : For USB */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_extern_1_interrupt(void) interrupt 2
{ CPU_extern_1_process();
}
/********************************************************************************/
/* fun_name : CPU_serial_1_interrupt() */
/* version : v1.00 */
/* created : xillinx */
/* descript : For uart */
/********************************************************************************/
void CPU_serial_1_interrupt(void) interrupt 4
{ if( RI==1)
{ RI=0;
UART_recv_isr_process();
}
else if(TI==1)
{ TI=0;
UART_xmit_isr_process();
}
}
/********************************************************************************/
/* fun_name : CPU_source_initialize() */
/* version : v1.00 */
/* created : xillinx */
/* descript : 控制CPU的資源使用 */
/********************************************************************************/
void CPU_source_initialize (void)
{ CPU_timer_0_initialize();
CPU_timer_2_initialize();
CPU_uart_serial_initial();
IT0 = 0x1; //* 選擇中斷類型: 0<==>低電平,1<==>下降沿
EX0 = 0x1; //* 外部中斷0
ET0 = 0x1; //* 定時器0
EX1 = 0x0; //* 外部中斷1
ET1 = 0x0; //* 定時器1
ES = 0x1; //* UART串口0
EA = 0x1; //* 全局中斷控制
}
/********************************************************************************/
/* fun_name : CPU_timer_0_interrupt() */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_timer_interrupt(void)
{ CPU_soft_timer_lo++;
system_timer++; //* for system time operator
CPU_001_tick_process();
if((CPU_soft_timer_lo&0x01)==0x0)
{ CPU_002_tick_process();
}
if((CPU_soft_timer_lo&0x03)==0x0)
{ CPU_004_tick_process();
}
if((CPU_soft_timer_lo&0x07)==0x0)
{ CPU_008_tick_process();
}
if((CPU_soft_timer_lo&0x0F)==0x0)
{ CPU_010_tick_process();
}
if((CPU_soft_timer_lo&0x1F)==0x0)
{ CPU_020_tick_process();
}
if((CPU_soft_timer_lo&0x3F)==0x0)
{ CPU_040_tick_process();
}
if((CPU_soft_timer_lo&0x7F)==0x0)
{ CPU_080_tick_process();
}
if((CPU_soft_timer_lo&0xFF)==0x0)
{ CPU_100_tick_process();
CPU_soft_timer_hi++;
if((CPU_soft_timer_hi&0x01)==0x0)
{ CPU_200_tick_process();
}
if((CPU_soft_timer_hi&0x03)==0x0)
{ CPU_400_tick_process();
}
}
}
/********************************************************************************/
/* fun_name : CPU_timer_2_interrupt() */
/* descript : 定時器2中斷 */
/* version : v1.00 */
/* created : xillinx */
/********************************************************************************/
void CPU_timer_2_interrupt(void) interrupt 5
{ TF2=0x0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -