📄 lcd.c
字号:
#include <msp430x14x.h>
#include "lcd.h"
void ST7920_ChkBusy(void)
{
delay_nms(10);
}
void ST7920_SendByte(unsigned char dat)
{
unsigned char i, d;
for(i=0;i<8;i++)
{
d=dat&0x80;
if(d)
SET_LCD_SID; //SID=0
else
CLR_LCD_SID; //SID=1
dat<<=1;
delay_nus(8);
SET_LCD_CLK; //CLK=1
delay_nus(8);
CLR_LCD_CLK; //CLK=0
delay_nus(8);
}
}
void ST7920_SendCmd(unsigned char dat)
{
unsigned char s;
SET_LCD_CS; //CS=1
delay_nus(8);
s=dat&0xf0;
ST7920_SendByte(0xf8);
ST7920_SendByte(s);
s=dat&0x0f;
s<<=4;
ST7920_SendByte(s);
delay_nus(8);
CLR_LCD_CS; //CS=0
delay_nus(200);
}
void ST7920_SendData(unsigned char dat)
{
unsigned char s;
SET_LCD_CS; //CS=1
delay_nus(8);
s=dat&0xf0;
ST7920_SendByte(0xfa);
ST7920_SendByte(s);
s=dat&0x0f;
s<<=4;
ST7920_SendByte(s);
delay_nus(8);
CLR_LCD_CS; //CS=0
}
void ST7920_Init(void)
{
delay_nms(40);
ST7920_SendCmd(0x30);
delay_nms(5);
ST7920_SendCmd(0x30);
delay_nms(3);
ST7920_SendCmd(0x0c);
delay_nms(5);
ST7920_SendCmd(0x01);
delay_nms(10);
ST7920_SendCmd(0x06);
delay_nms(10);
}
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
switch(y)
{
case 0:
address = 0x80 + x;
break;
case 1:
address = 0x90 + x;
break;
}
ST7920_SendCmd(address );
}
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
ST7920_SendData( *s );
s ++;
delay_nms(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -