不会判断.望高手指点
*/
[pre]#include <iom16v.h>[/pre][pre]#define RS_CLR PORTD &= ~(1 << PD3)
#define RS_SET PORTD |= (1 << PD3)[/pre][pre]#define RW_CLR PORTD &= ~(1 << PD4)
#define RW_SET PORTD |= (1 << PD4)[/pre][pre]#define EN_CLR PORTD &= ~(1 << PD6)
#define EN_SET PORTD |= (1 << PD6)[/pre][pre]/*延时函数*/
void delay_us(unsigned int n) {[/pre][pre] if (n == 0) {
return ;
}
while (--n);
}[/pre][pre]/*延时函数*/
void delay_ms(unsigned char i) {[/pre][pre] unsigned char a, b;
for (a = 1; a < i; a++) {
for (b = 1; b; b++) {
;
}
}
}[/pre][pre]/*显示屏命令写入函数*/
void LCD_write_com(unsigned char com) {
RS_CLR;
RW_CLR;
EN_SET;
PORTB = com;
delay_us(5);
EN_CLR;
}[/pre][pre]/*显示屏命令写入函数*/
void LCD_write_data(unsigned char data) {[/pre][pre] RS_SET;
RW_CLR;
EN_SET;
PORTB = data;
delay_us(5);
EN_CLR;
}[/pre][pre]/*显示屏清空显示*/
void LCD_clear(void) {[/pre][pre] LCD_write_com(0x01);
delay_ms(5);
}[/pre][pre]/*显示屏字符串写入函数*/
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s) {
if (y == 0) {
LCD_write_com(0x80 + x);
}
else {
LCD_write_com(0xC0 + x);
}
while (*s) {
LCD_write_data( *s);
s ++;
}
}[/pre][pre]/*显示屏单字符写入函数*/
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data) {
if (y == 0) {
LCD_write_com(0x80 + x);
}
else {
LCD_write_com(0xC0 + x);
}
LCD_write_data( data);
}[/pre][pre]/*显示屏初始化函数*/
void LCD_init(void) {
DDRB = 0xFF; /*I/O口方向设置*/
DDRD |= (1 << PD3) | (1 << PD4) | (1 << PD6);
LCD_write_com(0x38); /*显示模式设置*/
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
delay_ms(5);
LCD_write_com(0x38);
LCD_write_com(0x08); /*显示关闭*/
LCD_write_com(0x01); /*显示清屏*/
LCD_write_com(0x06); /*显示光标移动设置*/
delay_ms(5);
LCD_write_com(0x0C); /*显示开及光标设置*/
}
[/pre]
[pre]
[/pre]
200字以内,仅用于支线交流,主线讨论请采用回复功能。