⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1620.h

📁 详细讲解PS/2键盘通信接口及协议
💻 H
字号:
/*本程序没有mian()函数,仅将LCD的几个常用操作写成相应的函数,
做成“LCD.h"的头文件*/
/*PORTA为LCDDATA输出
 控制端分别为PB0……2
 void Write_String(uint8_t *s) 写字符串
 void Initialize_LCD(void) 初始化LCD
 void Write_Word(uint8_t row,uint8_t colum ,uint8_t Data) 写字
 */

#include<avr/io.h>
#include<inttypes.h>

#define LCDPORT PORTA
#define LCDDDR  DDRA
#define LCDPIN  PINA
     
#define En_H    sbbi(2)
#define En_L    cbbi(2)
#define RW_R    sbbi(1)
#define RW_W    cbbi(1)
#define RS_H    sbbi(0)
#define RS_L    cbbi(0)
#define DelaytE  Delay(10)
#define Clear_Screen Write_Command(0x01)


void sbbi(uint8_t a)
{
 PORTB|=1<<a;
 }
 void cbbi(uint8_t a)
 {
   uint8_t b=0xfe;
   for(;a>0;a--)
    {
	 b<<=1;
	 b|=0x01;
	}
   PORTB&=b;
 }
void Delay(uint16_t time)
{
  while(time>0)
    time--;
}

void En_Toggle(void)
{
En_H;
DelaytE;
En_L;
DelaytE;
}

void Wait_Until_Ready(void)
{
RW_R;
RS_L;
LCDDDR=0X00;
LCDPORT=0X00;
En_H;
DelaytE;
loop_until_bit_is_clear(LCDPIN,7);
En_L;
}
void Write_Command(uint8_t Command)
{
RW_W;
RS_L;
LCDDDR=0XFF;
LCDPORT=Command;
En_Toggle();
Wait_Until_Ready();
}
void Write_Data(uint8_t Data)
{
RW_W;
RS_H;
LCDDDR=0XFF;
LCDPORT=Data;
En_Toggle();
Wait_Until_Ready();
}
void Write_Position(uint8_t row,uint8_t colum)
{
uint8_t p;
if(row==1)
 {
   p=0x80+colum-1;
   Write_Command(p);
   }
 else
  {
   p=0xC0+colum-1;
   Write_Command(p);
   }
 }
 void Write_String(uint8_t *s)
 {
 for(;*s!='\0';s++) 
  Write_Data(*s);
  }
  void Initialize_LCD(void)
  {
  DDRB=0xff;
  Write_Command(0x38);
  Write_Command(0x06);
  Write_Command(0x0c);
  Clear_Screen;
  }
  void Write_Word(uint8_t row,uint8_t colum ,uint8_t Data)
  {
   Write_Position(row,colum);
   Write_Data(Data);
   }
   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -