#include "VRS51L3074_Keil.h"
void timer_init(void)
{
PERIPHEN1 |= 0x03;// ʹÄÜTimer0 Timer1
T0T1CFG = 0x00; //ÅäÖö¨Ê±Æ÷0
T0T1CLKCFG = 0x73; //40MHz timer0 CLK_T0(200nS)
= CLK_SYS/8
// timer1 CLK_T1(3200ns) = CLK_SYS/128
T0CON = 0x04; //start T0
TH0 = 0x9E;
TL0 = 0x57; //timer0 clk 5MHz, 5ms--0verflow time
RCAP0H = 0x9E;
RCAP0L = 0x57;
T1CON = 0x04; //start T1
TH1 = 0x0b;
TL1 = 0xdb; //timer1 clk 312.5kHz, 200ms--0verflow time
INTSRC1 = 0x00; //set interrupt source T0(bit3=0)
T1(bit7=0)
INTEN1 |= 0x88; //enable T1(bit7=1) T0(bit3=1)
interrupt
}
////////////////////////
//Ãû³Æ£º Oscillator_init
//²ÎÊý£ºÎÞ
//·µ»ØÖµ£ºÎÞ
//¹¦ÄÜ£º³õʼ»¯¾§Õñ
////////////////////////
void Oscillator_init(void)
{
DEVCLKCFG1 = 0x40;//0x62; // 60H: 40M
DEVCLKCFG2 = 0x40;//0xc4; // 40H
}
void Peripheral_en(void)
{
PERIPHEN1 = 0x20; //Enable I2C
PERIPHEN2 = 0x08; //Enable IO Ports
DEVIOMAP = 0x10; //ʹÓÃÌæ»»½Å
PERIPHEN1 |= 0x18; //enable UART0, 1.
}
void IOport_init(void)
{
PERIPHEN2 |= 0x08;
// When:1 = I/O pin acts as a input (reset value)
// 0 = I/O pin acts as a output
P0PINCFG = 0x00; //0xff; // LCD Data[0..7]
P1PINCFG = 0x00; //Leds.
P2PINCFG = 0x00; //LCD selects.
P3PINCFG = 0x00; //0xff; //input.
P4PINCFG = 0x3e; //Lcd_BG.
P5PINCFG = 0x00; //unused. output.
P6PINCFG = 0xff; //keys.
P1 = 0x00; //initial P1 low.
}
void Interrupts_Init()
{
GENINTEN = 0x02;//Set the PININTCFG bit before configuring the INT0
pin event
//This will prevent receiving an inadvertant INT0 interrupt to be
triggered
//at the moment INT0 trigerring event is configured as Rising edge
INTSRC1 |= 0x01; //INT0 vector source = INT0,
IPINSENS1 |= 0x01; //Set INT0, INT1 sensitive on edge(1) or
Level(0)
IPININV1 = 0x00; //Set INT0, INT1 Pin sensitivity on Low
Level/Inversion
INTEN1 |= 0x01; //Enable INT0 (bit0) Interrupt
IPINFLAG1 &= 0xfe;
GENINTEN = 0x01; //Enable Global interrupt
}
void uart_init()
{
//--³õʼ»¯ UART0 at 115200bps @ 40MHz
DEVIOMAP &= 0xf7; // UART0 ʹÓà TXD
---> P3.1 & RXD ---> P3.0
// DEVIOMAP |= 0x08; // UART0 ʹÓà TXD ---> P2.3
& RXD ---> P2.4
UART0CFG = 0xE0; // Fine adjustment on baud rate ²¨ÌØÂÊ΢µ÷Öµ: 15
//Use internal clock ʹÓÃÆ¬ÄÚÕñµ´Æ÷ʱÖÓÔ´
//9th bit not used 8λÊý¾Ý
//only one stop bit 1λֹͣλ
UART0EXT = 0x00; //Not using UART0 Extensions
//
TimerÓÃ×÷²¨ÌØÂÊ·¢ÉúÆ÷ (¶¨Ê±Æ÷ģʽ½ûÖ¹)
//
¶à´¦ÀíÆ÷ģʽ½ûÖ¹
//
·¢ËÍǰ¼à²âRXÐźÅλ½ûÖ¹(±ê×¼UARTģʽ)
UART0BRL = 0x09;//ÅäÖò¨ÌØÂÊ Reload for 115200
UART0BRH = 0x00;
UART0INT = 0x62; //ʹÄÜ ½ÓÊÕÖжϼ°½ÓÊÕÒç³öÖÐ¶Ï Enable RX AV +
RXO V
//
³åÍ»ÖжϽûÖ¹
//
·¢ËÍ»º³å¿ÕÖжϽûÖ¹
// ½ÓÊÕÔÊÐí
//--initialize UART0 at 115200bps @ 39.2MHz
DEVIOMAP |= 0x10; // UART1 use TXD in
Pin40 & RXD in Pin41
UART1CFG = 0xE0; //No Fine adjustment on baud rate
//Use internal clock
//9th bit not used
//only one stop bit
UART1INT = 0x62; //Enable RX AV + RXO V int + Enable Reception
UART1EXT = 0x00; //Not using UART1 Extensions
UART1BRL = 0x09; //Reload for 115200
UART1BRH = 0x00; //
}
void keypad_init()
{
PERIPHEN2 |= 0x08;
/*
BIT7 - PWC1EN 0.disable 1.enable
BIT6 - PWC0EN 0.disable 1.enable
BIT5 - AUEN 0.disable 1.enable
BIT4 - XRAM2CODE 0.disable 1.enable
BIT3 - IOPORTEN 0.disable 1.enable
BIT2 - WDTEN 0.disable 1.enable
BIT1 - PWMSFREN 0.disable 1.enable
BIT0 - FPIEN 0.disable 1.enable
*/
PORTINEN |=0x40;
/*
bit7. Reserved (0) Keep this bit at 0
bit6. Port 6 Input Enable Register
0 = Port 6 input logic is deactivated
1 = Port 6 input logic is activated
bit5~bit0 ͬbit6
*/
P6PINCFG = 0xf0; // When: 1: input (reset value) 0:
output
// columns are input rows are output
P6 = 0x00;
}
void System_init(void)
{
Oscillator_init();
Peripheral_en();
timer_init();
uart_init();
IOport_init();
keypad_init();
Interrupts_Init();
}