?? lcd.c
字號:
#include <msp430xw42x.h>
void DELAY(void)
{
_NOP();
_NOP();
_NOP();
_NOP();
}
/**** LCD DRIVER MODE SUB. **************
;WRITE COMMAND SUB. ***********/
void WRCOM(unsigned char _COM)
{
unsigned char R7,M;
// R7=9; //LOOP=DATA 8 BIT +1X
P3OUT|=BIT0; // /CS=1
_NOP();
DELAY();
P3OUT&=~(BIT0); // /CS=0
DELAY();
P3OUT&=~(BIT2); // /WR=0
DELAY();
_NOP();
P3OUT|=BIT1; //D=1 (100)
DELAY();
_NOP();
P3OUT|=BIT2; //WR=1
DELAY();
_NOP();
P3OUT&=~(BIT2); //WR=0
DELAY();
_NOP();
P3OUT&=~(BIT1); //D=0
DELAY();
_NOP();
P3OUT|=BIT2; //WR=1
DELAY();
_NOP();
P3OUT&=~(BIT2); //WR=0
DELAY();
_NOP();
P3OUT&=~(BIT1); //D=0
DELAY();
_NOP();
P3OUT|=BIT2; // WR=1
DELAY();
_NOP();
M=_COM;
for (R7=0;R7<=8;R7++)
{
DELAY();
_NOP();
P3OUT&=~(BIT2); //WR=0
DELAY();
if ((M&0x80)==0) P3OUT&=~(BIT1); //DATA=0
else P3OUT|=BIT1; //DATA=1
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
M=M<<1;
}
}
//WRITE DATA SUB.*********************************************
void WRDD(unsigned char _COM)
{
unsigned char R6,M;
P3OUT|=BIT0; // CS=1
_NOP();
DELAY();
P3OUT&=~(BIT0); // CS=0
DELAY();
P3OUT&=~(BIT2); // WR=0
DELAY();
P3OUT|=BIT1; //D=1 (101)
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
P3OUT&=~(BIT2); //WR=0
DELAY();
P3OUT&=~(BIT1); //D=0
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
P3OUT&=~(BIT2); //WR=0
DELAY();
P3OUT|=BIT1; //D=1
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
M=_COM;
for (R6=0;R6<=5;R6++)
{
DELAY();
_NOP();
P3OUT&=~(BIT2); //WR=0
DELAY();
if ((M&0x80)==0)
{
P3OUT&=~(BIT1); //DATA=0
// DELAY();
}
else
{
// _NOP();
// DELAY();
P3OUT|=BIT1; //DATA=1
// DELAY();
}
_NOP();
DELAY();
P3OUT|=BIT2; // WR=1
DELAY();
M=M<<1;
}
}
void WRDA(unsigned char _COM)
unsigned char R5,M;
M=_COM;
for (R5=0;R5<=3;R5++)
{
_NOP();
DELAY();
P3OUT&=~(BIT2); //WR=0
DELAY();
// M=_COM;
if ((M&0x01)==0)
{
P3OUT&=~(BIT1); //DATA=0
//DELAY();
}
else
{
// _NOP();
// DELAY();
P3OUT|=BIT1; //DATA=1
// DELAY();
}
_NOP();
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
M=M>>1;
}
}
/*
void lianxu(void)
{
unsigned char R6;
char a[12]={0x01,0x04,0x00,0x01,0x03,0x05,0x01,0x07,0x04,0x01,0x05,0x02};
P3OUT|=BIT0; //CS=1
_NOP();
DELAY();
P3OUT&=~(BIT0); // CS=0
DELAY();
P3OUT&=~(BIT2); // WR=0
DELAY();
P3OUT|=BIT1; // D=1 (101)
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
P3OUT&=~(BIT2); //WR=0
DELAY();
P3OUT&=~(BIT1); // D=0
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
P3OUT&=~(BIT2); //WR=0
DELAY();
P3OUT|=BIT1; //D=1
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
for (R6=0;R6<6;R6++)
P3OUT&=~(BIT2); // WR=0
DELAY();
P3OUT&=~(BIT1); // DATA=0
DELAY();
P3OUT|=BIT2; //WR=1
DELAY();
}
for (R6=0;R6<12;R6++)
{
WRDA(a[R6]);
}
}
*/
void display(float num)
{
unsigned char shu[10][3]={{0x01,0x06,0x07},{0x01,0x04,0x00},{0x01,0x03,0x05},{0x01,0x07,0x04},{0x01,0x05,0x02},{0x00,0x07,0x06},{0x00,0x07,0x07},{0x01,0x06,0x00},{0x01,0x07,0x07},{0x01,0x07,0x06}};
unsigned char intpart[10],dotpart[10],s[10];
unsigned long temp,tempoten;
unsigned char i,k,x,y;//i,k用于整數部分,x,y用于小數部分
float dotp;
for (k=0;k<10;k++)
{
intpart[10]=0;
dotpart[10]=0;
s[10]=0;
}
i=0;
k=0;
x=0;
y=0;
temp=(long)num;
tempoten=temp/10;
while(tempoten!=0)
{
intpart[i]=temp-10*tempoten; //
temp=tempoten;
tempoten=temp/10;
i++;
}
intpart[i]=temp;
/*
for (k=0;k<=i;k++)
{
WRDA(shu[intpart[k]][0]);
WRDA(shu[intpart[k]][1]);
WRDA(shu[intpart[k]][2]);
}*/
dotp=num-(long)num;
while(dotp!=0)
{
dotpart[x]=(char)(dotp*10);
dotp=dotp*10.0;
dotp=dotp-(char)dotp;
x++;
}
x=7-i;
for (y=0;y<x;y++)
{
s[y]=dotpart[x-1-y];
}
for (y=0;y<=i;y++)
{
s[x+y]=intpart[y];
}
WRDD(0x00);
for (k=0;k<x;k++)
{
WRDA(shu[s[k]][0]);
WRDA(shu[s[k]][1]);
WRDA(shu[s[k]][2]);
}
WRDA((shu[s[x]][0])+0x04);
WRDA(shu[s[k]][1]);
WRDA(shu[s[k]][2]);
for (k=x+1;k<=x+i;k++)
{
WRDA(shu[s[k]][0]);
WRDA(shu[s[k]][1]);
WRDA(shu[s[k]][2]);
}
}
void clear_display(void)
{
unsigned char k;
WRDD(0x00); //CLEAR DISPLAY
for (k=0;k<30;k++)
{
WRDA(0x00); //FIRST ADDR
}
}
void Initial_lcd(void)
{
unsigned int k;
P3DIR|=BIT0+BIT1+BIT2;
P3OUT|=BIT0+BIT1+BIT2;
for (k = 0xffff; k > 0; k --); // 延時
for (k = 0xffff; k > 0; k --); // 延時
for (k = 0xffff; k > 0; k --); // 延時
for (k = 0xffff; k > 0; k --); // 延時
WRCOM(0x24); //00100100B ;INITIALIZE
WRCOM(0x14); //00010100B ;32768HZ
WRCOM(0x01); //00000001B ;SYS EN
WRCOM(0x03); //00000011B ;LCD ON
clear_display();
WRDD(0x00);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -