/*
* lcd1602.c
*
* Created: 2014/4/19 14:14:53
* Author: zxl
*/
#include <avr/io.h>
#define uint unsigned int
#define uchar unsigned char
int i0_init();
int lcd_init();
int lcd_set_xy(uchar x,uchar y);
int lcd_writechar(uchar a,uchar b,uchar c);
int lcd_puts(uchar *str,uchar len);
int check_busy();
int Delay_us(uint t);
int Delay_ms(uint t);
int i0_init()
{
DDRA=0x00;
PORTA=0x00;
DDRB|=(1<<PB0)|(1<<PB1)|(1<<PB2);
PORTB|=(1<<PB0)|(1<<PB1)|(1<<PB2);
return 0;
}
//LCD初始化
int lcd_init()
{
Delay_ms(100);
lcd_writechar(0x38,0,0);
Delay_ms(60);
lcd_writechar(0x38,0,0);
Delay_ms(60);
lcd_writechar(0x38,0,0);
lcd_writechar(0x38,0,1);
lcd_writechar(0x08,0,1);
lcd_writechar(0x01,0,1);
lcd_writechar(0x06,0,1);
lcd_writechar(0x0c,0,1);
return 0;
}
//该函数清除LCD的显示,并显示位置回到第0行和0列的起始位置
/*int lcd_clear()
{
}*/
//该函数将显示的位置定在第x行,y列处,注意LCD列行定位都是0开始的
int lcd_set_xy(uchar x,uchar y)
{
x&=0x01;
y&=0x0f;
if (x)
lcd_writechar(0x80+0x40+y,0,1);
else
lcd_writechar(0x80+y,0,1);
return 0;
}
//该函数字符c将在显示的位置显示出来
int lcd_writechar(uchar a,uchar b,uchar c)
{
if (c)
{
check_busy();
DDRA=0xff;
}
if (b)
PORTB|=(1<<PB0);
else
PORTB=~(1<<PB0);
PORTB=~(1<<PB1);
PORTA=a;
PORTA|=(1<<PA2);
Delay_us(1);
PORTA=~(1<<PA2);
return 0;
}
//该函数将从当前的位置显示开始,显示定义在SRAM中的字符串(str为SRAM中定义的字符串指针)
int lcd_puts(uchar *str,uchar len)
{
uchar i;
if (len>16)
{
for(i=0;i<16;i++)
{
lcd_writechar(str[i],1,1);
}
lcd_set_xy(1,0);
for (i=16;i<len;i++)
{
lcd_writechar(str[i],1,1);
}
}
else
for (i=0;i<len;i++)
{
lcd_writechar(str[i],1,1);
}
return 0;
}
//该函数将从当前的位置显示开始,显示定义在flash中的字符串(str为flash中定义的字符串指针)
/*int lcd_putsf(char flash *str)
{
}*/
int check_busy()
{
DDRA=0x00;
PORTA=0x00;
PORTB|=(1<<PB1)|(1<<PB2);
Delay_us(1);
while (PINA&0x80);
PORTB=~(1<<PB2);
return 0;
}
int Delay_us(uint t)
{
while(--t);
return 0;
}
int Delay_ms(uint t)
{
while(t--)
{
Delay_us(1000);
}
return 0;
}
int main(void)
{
uchar dis_buffer[]="blueavr2,by bluemcu!";
lcd_init();
i0_init();
while(1)
{
lcd_writechar(dis_buffer,25,1);
}
}
提示警告改怎么解决谢谢
Warning 2 expected 'unsigned char' but argument is of type 'unsigned char *' C:UserszxlDesktopavrlcd1602lcd1602lcd1602.c 64 5 lcd1602
Warning 1 passing argument 1 of 'lcd_writechar' makes integer from pointer without a cast [enabled by default] C:UserszxlDesktopavrlcd1602lcd1602lcd1602.c 142 8 lcd1602
此帖出自
小平头技术问答
一周热门 更多>