TA的每日心情 | 奋斗 2014-7-16 09:10 |
---|
签到天数: 361 天 连续签到: 1 天 [LV.8]以坛为家I
|
本帖最后由 xinxincaijq 于 2012-9-4 17:14 编辑
3根线驱动12864
#include <MSP430G2553.h>
#include "lcd12864.h"
uint i;
uchar Table1[]="频率跟踪系统";
uchar Table2[]="频率:";
uchar Table3[]="Hz";
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
init();
while(1)
{
display_char(Table1,0,1);
delay(15);
display_char(Table2,1,0);
delay(15);
display_char(Table3,1,7);
}
}
#ifndef lcd12864_H_
#define lcd12864_H_
# include<MSP430G2553.h>
#define uchar unsigned char
#define uint unsigned int
#define CS_H P2OUT|=BIT0 //P10 cs
#define CS_L P2OUT&=~BIT0
#define SCLK_H P2OUT|=BIT1 //P11 sclk
#define SCLK_L P2OUT&=~BIT1
#define SID_H P2OUT|=BIT2 //P12 SID
#define SID_L P2OUT&=~BIT2
void init();
void delay(uint);
void sendbyte(uchar);
void write_com(uchar); //写指令
void write_dat(uchar); //写数据
void lcd_pos(uchar X,uchar Y);//确定位置
void display(uint);
void display_char(uchar *,uchar,uchar);
void go (uint);
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
pos = X+Y ;
write_com(pos); //显示地址
}
void init()
{
delay(2);
write_com(0x30); //30--基本指令动作
delay(5);
write_com(0x0c); //光标右移画面不动
delay(5);
write_com(0x01); //清屏
delay(5); //清屏时间较长
write_com(0x06); //显示打开,光标开,反白关
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void sendbyte(uchar zdata)
{
unsigned int i;
for(i=0; i<8; i++)
{
P2DIR=0xff;
if((zdata << i) & 0x80)
{
SID_H;
}
else
{
SID_L;
}
SCLK_L;
SCLK_H;
}
}
void write_com(uchar cmdcode)
{ P2DIR=0xff;
CS_H;
sendbyte(0xf8);
sendbyte(cmdcode & 0xf0);
sendbyte((cmdcode << 4) & 0xf0);
delay(2);
}
void write_dat(uchar Dispdata)
{ P2DIR=0xff;
CS_H;
sendbyte(0xfa);
sendbyte(Dispdata & 0xf0);
sendbyte((Dispdata << 4) & 0xf0);
delay(2);
}
void display(uint num)
{
uchar qian,bai,shi,ge;
qian=num/1000;
bai=num%1000/100;
shi=num%1000%100/10;
ge=num%10;
write_dat(0x30+qian);
write_dat(0x30+bai);
write_dat(0x30+shi);
write_dat(0x30+ge);
}
void display_char(uchar * pointer,uchar X,uchar Y)
{
lcd_pos(X,Y);
while(*pointer!='\0')
{
write_dat(*pointer);
pointer++;
}
}
#endif /* lcd12864_H_ */
|
|