这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 1986330 MCU DIY进程帖

共22条 3/3 1 2 3 跳转至
助工
2011-12-26 11:23:47     打赏
21楼

LCD1602操作程序
#define  LCD_DB P0
sbit LCD_RS = P2^4;
sbit LCD_RW = P2^5;
sbit LCD_E  = P2^6;
/**********************************************************/
void delay_n40us(unsigned int n)
{
 unsigned int i;
 unsigned char j;
 for(i=n;i>0;i--)
  for(j=0;j<2;j++);
}
/**********************************************************/
void LCD_write_command(unsigned char dat)
{
 LCD_DB = dat;
 LCD_RS = 0;
 LCD_E  = 1;
 LCD_E  = 0;
 delay_n40us(1);
}
/**********************************************************/
void LCD_write_data(unsigned char dat)
{
 LCD_DB = dat;
 LCD_RS = 1;
 LCD_RW = 0;
 LCD_E  = 1;
 LCD_E  = 0;
 delay_n40us(1);
}
/**********************************************************/
void LCD_disp_char(unsigned char x,unsigned char y,unsigned char dat)
{
 unsigned char address;
 if(y==1)
  address = 0x80 + x;
 else
  address = 0xc0 + x;
 LCD_write_command(address);
 LCD_write_data(dat);
}
/**********************************************************/
void LCD_check_busy(void)
{
 do{
  LCD_E = 0;
  LCD_RS = 0;
  LCD_RW = 1;
  LCD_DB = 0xff;
  LCD_E = 1;
 }while(LCD_DB^7 == 1);
}
/**********************************************************/
void LCD_init(void)
{
 LCD_write_command(0x38);
 LCD_write_command(0x0c);
 LCD_write_command(0x06);
 LCD_write_command(0x01);
 delay_n40us(100);
}
/**********************************************************/


助工
2011-12-26 11:25:05     打赏
22楼
所有代码均可在同一主程序内运行
可将所有资源同时使用

共22条 3/3 1 2 3 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]