引脚配置:
P7.0: RS
P7.1: RW
P7.2: E
P2 : 数据
代码:
void delay_ms(UINT n)
{
UINT i;
for (i=0;i<n;i++)
{
TAU0_Channel0_Start();
do
{
}
while (TimerFlag==0);
TAU0_Channel0_Stop();
TimerFlag=0;
}
}
void LCD_init(void)
{
LCD_write_command(0x33);
LCD_write_command(0x0c);
LCD_write_command(0x06);
LCD_write_command(0x01);
delay_ms(4);
}
void LCD_write_command(UCHAR command)
{
P2=command;
delay_ms(1);
PORT_ChangeP70Output(0);
delay_ms(1);
PORT_ChangeP71Output(0,0);
delay_ms(1);
PORT_ChangeP72Output(1);
delay_ms(1);
PORT_ChangeP72Output(0);
delay_ms(4);
}
void LCD_write_data(UCHAR dat)
{
P2=dat;
PORT_ChangeP70Output(1);
delay_ms(1);
PORT_ChangeP71Output(0,0);
delay_ms(1);
PORT_ChangeP72Output(1);
delay_ms(1);
PORT_ChangeP72Output(0);
delay_ms(4);
}
void LCD_disp_char(UCHAR x,UCHAR y,UCHAR dat)
{
UCHAR address;
if(y==1)
address=0x80+x;
else if(y==2)
address=0xc0+x;
LCD_write_command(address);
delay_ms(2);
LCD_write_data(dat);
delay_ms(2);
}
void LCD_disp_string(UCHAR x,UCHAR y,UCHAR *s)
{
UCHAR address;
if(y==1)
address=0x80+x;
else if(y==2)
address=0xc0+x;
LCD_write_command(address);
delay_ms(2);
while(*s)
{
LCD_write_data(*s);
delay_ms(2);
s ++;
}
}
void main(void)
{
/* Start user code. Do not edit comment generated here */
ADPC = _01_ADPC_DI_ON;
LCD_init();
LCD_disp_string(0,1,"Renesas @EEPW");
while (1U)
{
;
}
/* End user code. Do not edit comment generated here */
}
为了进行AD实验,对LCD驱动作了改造,用P5.2-P5.5作为LCD的数据传送端口,以便让出P2用作AD输入。
相关函数如下:
void delay_ms(UINT n)
{
UINT i;
for (i=0;i<n;i++)
{
TAU0_Channel0_Start();
do
{
}
while (TimerFlag==0);
TAU0_Channel0_Stop();
TimerFlag=0;
}
}
void LCD_init(void) //初始化LCD
{
LCD_write_command(0x28); //4位数据模式
LCD_write_command(0x0c); //显示开
// LCD_write_command(0x06);
LCD_write_command(0x01); //清屏
delay_ms(4);
}
void LCD_en_write(void) //液晶使能
{
delay_ms(1);
PORT_ChangeP71Output(0,0);
delay_ms(1);
PORT_ChangeP72Output(1);
delay_ms(1);
PORT_ChangeP72Output(0);
delay_ms(4);
}
void LCD_write_command(UCHAR command) //写指令
{
UCHAR tmp;
PORT_ChangeP70Output(0); //RS=0
delay_ms(1);
tmp =command;
tmp &=0xf0; //取高4位
tmp =tmp>>2; //右移2位
P5 &=0xc3; //清
P5 =tmp; //写高4位
LCD_en_write();
tmp =command;
tmp &=0x0f; //取高4位
tmp =tmp<<2; //左移2位
P5 &=0xc3; //清
P5 =tmp; //写低4位
LCD_en_write();
}
void LCD_write_data(UCHAR dat) //写数据
{
UCHAR tmp;
PORT_ChangeP70Output(1); //RS=1
delay_ms(1);
tmp =dat;
tmp &=0xf0; //取高4位
tmp =tmp>>2; //右移2位
P5 &=0xc3 ; //清
P5 =tmp; //写高4位
LCD_en_write();
tmp =dat;
tmp &=0x0f; //取高4位
tmp =tmp<<2; //左移2位
P5 &=0xc3; //清
P5 =tmp; //写低4位
LCD_en_write();
}
void LCD_disp_char(UCHAR x,UCHAR y,UCHAR dat) //显示字符
{
UCHAR address;
if(y==1)
address=0x80+x;
else if(y==2)
address=0xc0+x;
LCD_write_command(address);
delay_ms(2);
LCD_write_data(dat);
delay_ms(2);
}
void LCD_disp_string(UCHAR x,UCHAR y,UCHAR *s)//显示字符串
{
UCHAR address;
if(y==1)
address=0x80+x;
else if(y==2)
address=0xc0+x;
LCD_write_command(address);
delay_ms(3);
while(*s)
{
LCD_write_data(*s);
delay_ms(3);
s ++;
}
}
主函数:
void main(void)
{
/* Start user code. Do not edit comment generated here */
// ADPC = _01_ADPC_DI_ON;
LCD_init();
// LCD_disp_char(0,1,0x49);
// LCD_disp_char(1,1,0x20);
// LCD_disp_char(2,1,0x4c);
//LCD_disp_char(3,1,0x4f);
// LCD_disp_char(4,1,0x56);
LCD_disp_string(0,1,"Renesas @EEPW");
LCD_disp_string(0,2,"Renesas @EEPW");
while (1U)
{
;
}
/* End user code. Do not edit comment generated here */
}
主函数:
void main(void)
{
/* Start user code. Do not edit comment generated here */
ADPC = _01_ADPC_DI_ON;
LCD_init();
AD_ComparatorOn(); /* Enable ADC voltage comparator (ADCE = on) */
AD_Start(); /* Start ADC (ADCS = 0n) */
while (1U)
{
if(ADC_done == MD_TRUE)
{
AD_Stop();
ADC_Result=ADC_Result /15;
ADC_Value=ADC_Result;
ADC_done = MD_CLEAR;
ADC_Value=ADC_Result%10 + 0x30;
LCD_disp_char(5,1,ADC_Value);
ADC_Result=ADC_Result/10;
ADC_Value=ADC_Result%10 + 0x30;
LCD_disp_char(4,1,ADC_Value);
ADC_Result=ADC_Result/10;
ADC_Value=ADC_Result%10 + 0x30;
LCD_disp_char(3,1,ADC_Value);
ADC_Result=ADC_Result/10;
ADC_Value=ADC_Result%10 + 0x30;
LCD_disp_char(2,1,'.');
LCD_disp_char(1,1,ADC_Value);
AD_Start();
}
else
{
NOP();
}
}
/* End user code. Do not edit comment generated here */
}
AD中断函数:
__interrupt void MD_INTAD(void)
{
/* Start user code. Do not edit comment generated here */
ADC_Result=ADCR;
// ADC_Result=ADC_Result>>5;
ADC_done = MD_SET;
/* End user code. Do not edit comment generated here */
}
视频稍后上传
回复
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |