?? led_serial.c
字號:
////////////////////////////////////////////////
//液晶驅(qū)動程序
//液晶型號:12232F
//使用SPCE061A連接方式:(串行)
//**\CS:IOB0,SID:IOB15,SCLK:IOB1**
////////////////////////////////////////////////
#include "SPCE061A.h"
#define CS_1 0x0001//液晶各個控制端定義
#define SID_1 0x8000
#define SCLK_1 0x0002
#define CS_H *P_IOB_Data|=CS_1
#define CS_L *P_IOB_Data&=(0xFFFF-CS_1)
#define SID_H *P_IOB_Data|=SID_1
#define SID_L *P_IOB_Data&=(0xFFFF-SID_1)
#define SCLK_H *P_IOB_Data|=SCLK_1
#define SCLK_L *P_IOB_Data&=(0xFFFF-SCLK_1)
#define Clear_Watchdog *P_Watchdog_Clear=0x0001
unsigned int Disp_Addr=0x0000;
////////////////////////////////////////////////
//function: delay
////////////////////////////////////////////////
void delay(unsigned int i)
{
while(i--)
Clear_Watchdog;
}
////////////////////////////////////////////////
//function: simulate the high and low level-
//according to the Send_Data
//input: the sent data
////////////////////////////////////////////////
void Send_Simulate(unsigned int Send_Data)
{
if(Send_Data&0x0080)
SID_H;
else
SID_L;
SCLK_H;
delay(8);
Clear_Watchdog;
SCLK_L;
}
////////////////////////////////////////////////
//function: send data or command
//input: data or command and their marks-
//individually
//mark=0:data
//mark=1:command
////////////////////////////////////////////////
void Serial_Send(unsigned int data,unsigned int mark)
{
unsigned int i,j,Com_or_Data;
switch(mark)
{
case 0:
Com_or_Data=0x00fa;
break;
case 1:
Com_or_Data=0x00f8;
break;
}
CS_H;//enable
for(i=1;i<=8;i++)//判斷發(fā)送數(shù)據(jù)或指令
{
Send_Simulate(Com_or_Data);
Com_or_Data<<=1;
Clear_Watchdog;
}
for(j=0;j<2;j++)//發(fā)送
{
for(i=4;i>=1;i--)
{
Send_Simulate(data);
data<<=1;
Clear_Watchdog;
}
for(i=4;i>=1;i--)
{
SID_L;
SCLK_H;
delay(8);
SCLK_L;
Clear_Watchdog;
}
}
CS_L;//disable
}
void Lcd_Initial()//LCD初始化
{
Serial_Send(0x0030,1);//功能設(shè)置:一次送8位數(shù)據(jù),基本指令集
Serial_Send(0x0004,1);//點設(shè)定:顯示字符/光標(biāo)從左到右移位,DDRAM地址加1
Serial_Send(0x000f,1);//顯示設(shè)定:開顯示,顯示光標(biāo),當(dāng)前顯示位反白閃動
Serial_Send(0x0001,1);//清DDRAM
Serial_Send(0x0002,1);//DDRAM地址歸位
Serial_Send(0x0080,1);//把顯示地址設(shè)為0X80,即為第一行的首位
}
////////////////////////////////////////////////
//function: select where to display
//input: line and row
//output:Disp_Addr(the globle variant)
////////////////////////////////////////////////
void Position_Select(int line,int row)
{
if(line==1)
Disp_Addr=0x80+row-1;
else
Disp_Addr=0x90+row-1;
}
////////////////////////////////////////////////
//function: display it at the address given
//input: line, row and the string
////////////////////////////////////////////////
void Disp_String(int line,int row,int string)
{
Position_Select(line,row);
Serial_Send(Disp_Addr,1);
Serial_Send(string,0);
}
////////////////////////////////////////////////
//function: display it at the address given
//input: line, row and the strings
////////////////////////////////////////////////
void Disp_Strs(int line,int row,char *strings)
{
int i;
Position_Select(line,row);
Serial_Send(Disp_Addr,1);
if(line==1)//如果定位在第一行,超過第一行的字符串則在第二行顯示
{
for(i=0;*(strings+i);i++)
{
Clear_Watchdog;
if((Disp_Addr+i/2)<0x87)
Serial_Send(*(strings+i),0);
else
break;
}
Serial_Send(0x90,1);
for(;*(strings+i);i++)
{
Serial_Send(*(strings+i),0);
Clear_Watchdog;
}
}
else//如果定位在第二行,超過第二行的字符串則在第一行顯示
{
for(i=0;*(strings+i);i++)
{
Clear_Watchdog;
if((Disp_Addr+i/2)<0x97)
Serial_Send(*(strings+i),0);
else
break;
}
Serial_Send(0x80,1);
for(;*(strings+i);i++)
{
Serial_Send(*(strings+i),0);
Clear_Watchdog;
}
}
}
int main()
{
unsigned char huan[]="好的源碼";
*P_IOB_Dir=0xffff;
*P_IOB_Attrib=0xffff;
*P_IOB_Data=0xffff;
Lcd_Initial();
Disp_Strs(1,1,huan);
Disp_String(2,7,'!');
while(1)
{
*P_Watchdog_Clear = 1;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -