文号
t14798
阅读
2934
回复
2
收藏
1
判断AVR单片机的接口
2009/04/30
IP:广东
不会判断.望高手指点

*/
[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] LCD.jpg [/pre]
17年9个月前IP:未同步
95918
1楼
我使用的是AVR ATmega16L 8PU
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的