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

📄 rt12232.txt

📁 液晶显示器rt12232的AVR程序
💻 TXT
字号:
#include <avr/io.h>

typedef unsigned char uchar;
typedef unsigned int  uint;
uchar ucBuffer;

#define set_CS  PORTA|=_BV(PA0)
#define clr_CS  PORTA&=~_BV(PA0)//CS

#define set_SID PORTA|=_BV(PA1)
#define clr_SID PORTA&=~_BV(PA1)//SID

#define set_CLK PORTA|=_BV(PA2)
#define clr_CLK PORTA&=~_BV(PA2)//CLK

void Delay()
{
        uchar i,j;
        for(i=0x0ff;i>0;i--)
      for(j=0x0ff;j>0;j--);
}
/***************************发送一字节数据******************/
void SendByte(uchar ucSendData)
{
        uchar i;
        for(i=8;i>0;i--)
        {
                clr_CLK;//上升沿发送数据
                if(ucSendData&0x80)//如果是1
                 set_SID;
                else
                 clr_SID;
                set_CLK;
                ucSendData=ucSendData<<1;//左移一位
        }
}

/*************************写控制指令***************************/
void Write_Command(uchar ucCommand) //按时序操作
{
        uchar temp=0xf8;//write command
          set_CS;//使能
        SendByte(temp);//send command,the first byte
        temp=ucCommand&0xf0;
        SendByte(temp);//send the second byte
        temp=(ucCommand<<4)&0xf0;
        SendByte(temp);//send the third byte
        clr_CS;
}

/************************写数据*********************************/
void Write_Data(uchar ucData)
{        
        set_CS;
        ucBuffer=0xfa;//数据从MCU到LCD,所写数据为显示数据
        SendByte(ucBuffer);//the first byte
        ucBuffer=ucData&0xf0;//高四位
        SendByte(ucBuffer);//the second byte
        ucBuffer=(ucData<<4)&0xf0;//低四位
        SendByte(ucBuffer);//the third byte
        clr_CS;
}

/***********************写汉字到LCD的指定位置**************/
void Lcd_Display(uchar x_data,uchar data1,uchar data2)
//x_data--RAM地址,data1--汉字编码高8位,data2--汉字编码低8位
{
        Write_Command(x_data);//指定显示地址
        Write_Data(data1);//汉字编码高8位
        Write_Data(data2);//汉字编码低8位
}

/**********************LCD初始化********************************/
void Lcd_Initial()
{
		DDRA|=_BV(PA0)|_BV(PA1);
	    DDRA|=_BV(PA2);
        Delay();//延时40MS
        Write_Command(0x30);//功能设定:8位数据,基本指令30
        Write_Command(0x06);//点设定:画面右移
        Write_Command(0x0c);//lcd开,光标关
        Write_Command(0x01);//清屏
        Write_Command(0x02);//地址归位
}
/************************main**********************************/
int  main()
{
        Lcd_Initial();
        Write_Command(0x80);//设定DDRAM起始地址
                 //汉字显示
       
		while(1)
		{
		   Lcd_Display(0x80,0xc4,0xcf);
        Lcd_Display(0x81,0xd1,0xf4);
        Lcd_Display(0x82,0xc0,0xed);
        Lcd_Display(0x83,0xb9,0xa4);
        Lcd_Display(0x84,0xd1,0xa7);
        Lcd_Display(0x85,0xd4,0xba);
        Lcd_Display(0x90,0xc0,0xee);
        Lcd_Display(0x91,0xcf,0xdc);
        Lcd_Display(0x92,0xc0,0xa4);
        Lcd_Display(0x93,0xa3,0xcc);//l
        Lcd_Display(0x94,0xa3,0xcf);//o
        Lcd_Display(0x95,0xa3,0xd6);//v
        Lcd_Display(0x96,0xa3,0xc5);//e
		}
 }       

⌨️ 快捷键说明

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