基于MSP430F149的KS0108(LCD)驱动程序
#include "math.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "ctype.h"
//#include "HZTable.h"
//#include "ASCII816.h"
#define uint unsigned int
#define uchar unsigned char
//**********************************************
/*#define RS BIT0
#define RW BIT1
#define E BIT2
#define CS1 BIT3
#define CS2 BIT4
#define RST BIT5
#define EL BIT6 //背光*/
#define RS 0x01//寄存器选择信号(0--Command, 1--data) ks0108()
#define RW 0x02//读/写选择信号
#define E 0x04//使能信号
#define CS1 0x02// 左屏
#define CS2 0x04// 右屏
#define RST 0x01
//数据线:p4口 ,控制线: p5口
//**********************************************
uchar cradd1,cradd2;
uchar item1[5]={0,1,2,3,50}; //欢迎使用
uchar item2[5]={4,5,6,7,50}; //请等待……
unsigned char hzbei[32]={
0x04,0x04,0x04,0xE4,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0xE4,0x04,0x06,0x04,0x00,
0x00,0x40,0x20,0x13,0x1A,0x42,0x82,0x7E,0x02,0x02,0x0A,0x13,0x30,0x60,0x00,0x00
};
//=======================================================
void short_delay(uint i)
{ uint j;
for(j=0;j<=i;j++);
}
void delayms(uchar tickms)
{ uchar count,i;
_NOP();
_NOP();
_NOP();
for(i=tickms;i>0;i--)
{ for(count=0;count<=58;count++) {;}
_NOP();
}
}
//**************************************************
void prl0(uchar com1)// 写指令代码子程序(左)
{
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT |=CS1; //csa=1
P1OUT&=~CS2; //csb=0
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |= E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
P3OUT&=~RW; //rw=0
P2DIR=0xff; //P2口为输出口
P2OUT=com1;
P3OUT |=E; //E=1
P3OUT&=~E; //E=0
}
//**************************************************
void prl1(uchar dat1)// 写显示数据子程序(左)
{
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT |=CS1; //csa=1
P1OUT&=~CS2; //csb=0
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |=E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
P3OUT |=RS; //rs=1
P3OUT&=~RW; //rw=0
P2DIR=0xff; //P2口为输出口
P2OUT=dat1;
P3OUT|=E; //E=1
P3OUT&=~E; //E=0
}
//**************************************************
void prr0(uchar com2)// 写指令代码子程序(右)
{
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT&=~CS1; //csa=0
P1OUT |=CS2; //csb=1
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |= E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
P3OUT&=~RW; //rw=0
P2DIR=0xff; //P2口为输出口
P2OUT=com2;
P3OUT |=E; //E=1
P3OUT&=~E; //E=0
}
//*************************************************
void prr1(uchar dat2)// 写显示数据子程序(右)
{
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT&=~CS1; //csa=0
P1OUT |=CS2; //csb=1
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |=E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
P3OUT |=RS; //rs=1
P3OUT&=~RW; //rw=0
P2DIR=0xff; //P2口为输出口
P2OUT=dat2;
P3OUT |=E; //E=1
P3OUT&=~E; //E=0
}
//****************************************************
//读显示数据子程序 (左屏)
//****************************************************
uchar ReadDatal(void)
{
uchar Rdata;
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT |=CS1; //csa=1
P1OUT&=~CS2; //csb=0
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |=E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
P3OUT |=RS; //RS=1
//P3OUT =RW; //R/W=1
P3OUT |=E; //E=1
Rdata=P2IN;
P3OUT&=~E; //E=0
return Rdata;
}
//****************************************************
//读显示数据子程序 (右屏)
//****************************************************
uchar ReadDatar(void)
{
uchar Rdata;
P3DIR =0X7F; //P3为输出口
P1DIR =0X7F; //P3为输出口
P1OUT&=~CS1; //csa=0
P1OUT |=CS2; //csb=1
P3OUT&=~RS;
P3OUT |=RW; //RS=0,R/W=1,以便读液晶状态
P2DIR=0x00; //P2口为输入口
do
{
P3OUT |=E; //E=1
cradd1=P2IN;
P3OUT&=~E; //E=0
}
while((cradd1&0x80)!=0);
MSP430F149KS0108LCD驱动程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)