#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvSYS.h"
#include "SysInfra.h"
#define rs_1 DrvGPIO_SetBit(E_GPC,14)
#define rs_0 DrvGPIO_ClrBit(E_GPC,14)
#define rw_1 DrvGPIO_SetBit(E_GPC,15)
#define rw_0 DrvGPIO_ClrBit(E_GPC,15)
#define en_1 DrvGPIO_SetBit(E_GPC,6)
#define en_0 DrvGPIO_ClrBit(E_GPC,6)
uint8_t table[]="祝菜地越办越红火";
//uint8_t table1[]="";
void delay_ms(uint32_t count)// 延时函数MS
{
uint32_t i,j;
for(i=count;i>0;i--)
for(j=2395;j>0;j--);
}
void RCC_init() //时钟初始化,选择12Ms
{
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
delay_ms(100);
LOCKREG();
}
void GPIO_init()
{
DrvGPIO_Open( E_GPA, 2, E_IO_OUTPUT ); //DB0~DB7
DrvGPIO_Open( E_GPA, 3, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 4, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 5, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 6, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 7, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 8, E_IO_OUTPUT );
DrvGPIO_Open( E_GPA, 9, E_IO_OUTPUT );
DrvGPIO_Open( E_GPC, 14, E_IO_OUTPUT ); //RS
DrvGPIO_Open( E_GPC, 15, E_IO_OUTPUT ); //R/W
DrvGPIO_Open( E_GPC, 6, E_IO_OUTPUT ); //EN
}
void WriteCom(uint32_t in_com)
{
int32_t com;
com=in_com;
com<<=2;
rs_0;
rw_0;
en_1;
delay_ms(1);
GPIOA->DOUT=com;
delay_ms(1);
en_0;
}
void WriteData(uint32_t in_data)
{
int32_t data;
data=in_data;
data<<=2;
rs_1;
rw_0;
en_1;
GPIOA->DOUT=data;
delay_ms(1);
en_0;
}
void lcd_init()
{
WriteCom(0x38);
delay_ms(10);
WriteCom(0x01);
delay_ms(10);
WriteCom(0x0c);
delay_ms(10);
WriteCom(0x06);
delay_ms(10);
WriteCom(0x80);
}
void display(void)
{
uint8_t i;
WriteCom(0x80);
for(i=0;i<16;i++)
{
WriteData(table[i]);
delay_ms(5);
}
}
int main(void)
{
//DrvSYS_ResetChip();
GPIO_init();
//DrvGPIO_Open(E_GPA,2,E_IO_OUTPUT);
RCC_init();
lcd_init();
//WriteCom(0x80);
//WriteData('a');
display();
while(1)
{
// DrvGPIO_ClrBit(E_GPA,2);
DrvGPIO_SetBit(E_GPA,5);
DrvGPIO_ClrBit(E_GPA,2);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,2);
DrvGPIO_ClrBit(E_GPA,3);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,3);
DrvGPIO_ClrBit(E_GPA,4);
delay_ms(100);
DrvGPIO_SetBit(E_GPA,4);
DrvGPIO_ClrBit(E_GPA,5);
delay_ms(100);
DrvSYS_Delay(5000);
// rs_0;
}
} |