?? driver_s1.c
字號(hào):
/*
* Copyright 2005,重慶市海德自動(dòng)化有限公司開發(fā)室
* All rights reserved.
*
*
* 文件名稱: DRIVER_S1.c
*
* 摘 要: OJMC4*8C顯示器件的串行驅(qū)動(dòng)程序,新華龍IDE調(diào)試,主控芯片C8051F330.
* 顯示漢字,顯示字符。
*
*
* 當(dāng)前版本: 1.0
* 作 者: 余小勇
* 開始日期: 2005年7月18日
* 完成日期: 2005年7月19日
*
*
* 其它說明: 1.時(shí)序正常
2.能清全屏
3.能顯示漢字和字符
4.串行通信模式,可顯示8*4共32個(gè)16點(diǎn)陣漢字
5.直接向80H-9FH的DDRAM寫入相應(yīng)內(nèi)碼
*/
//-----------------------------------------------------------------------------
//頭文件包含
//-----------------------------------------------------------------------------
#include <c8051f330.h>
#include <intrins.h>
//-----------------------------------------------------------------------------
// 位定義
//-----------------------------------------------------------------------------
unsigned char bdata TEMP; //RW,RS暫存位尋址寄器定義
sbit CS=P0^2; //4腳CS
sbit STD=P0^0; //5腳R/W
sbit SCLK=P0^1; //6腳E
sbit RW=TEMP^0; //RW暫存位
sbit RS=TEMP^1; //RS暫存位
//-----------------------------------------------------------------------------
// 定義函數(shù)
//-----------------------------------------------------------------------------
void SYSCLK_Init (void); //主芯片初始化
void LCD_Init (void); //LCD初始化
void CLR_Screen (void); //LCD清屏
void SEND_Byte (unsigned char LCD_Byte); // 發(fā)送一個(gè)字節(jié)
void DELAY(unsigned int count); //延時(shí)COUNT*1US
void DISPLAY(unsigned char h,unsigned char l,unsigned char LCD_data_H,unsigned char LCD_data_L); //在h行,l列的位置顯示指定漢字字符,行(0-3),列(0-7)
//-----------------------------------------------------------------------------
// 主程序
//-----------------------------------------------------------------------------
void main(){
SYSCLK_Init(); //主芯片初始化
DELAY(65000);
LCD_Init(); // LCD初始化
while(1){
DISPLAY(0,1,0xd6,0xd8); //內(nèi)碼“重”
DELAY(50);
DISPLAY(0,2,0xc7,0xec); //內(nèi)碼“慶”
DELAY(50);
DISPLAY(0,3,0xba,0xa3); //內(nèi)碼“海”
DELAY(50);
DISPLAY(0,4,0xb5,0xc2); //內(nèi)碼“德”
DELAY(50);
DISPLAY(0,5,0xb9,0xab); //內(nèi)碼“公”
DELAY(50);
DISPLAY(0,6,0xcb,0xbe); //內(nèi)碼“司”
DELAY(50);
DISPLAY(1,0,0x31,0x32);
DELAY(50);
DISPLAY(1,1,0x33,0x34);
DELAY(50);
DISPLAY(1,2,0x35,0x36);
DELAY(50);
DISPLAY(1,3,0x37,0x38);
DELAY(50);
DISPLAY(1,4,0x39,0x40);
DELAY(50);
DISPLAY(1,5,0x41,0x42);
DELAY(50);
DISPLAY(1,6,0x43,0x44);
DELAY(50);
DISPLAY(1,7,0x45,0x46);
DELAY(50);
DISPLAY(2,0,0x47,0x48);
DELAY(50);
DISPLAY(2,1,0x4a,0x4b);
DELAY(50);
DISPLAY(2,2,0x4c,0x4d);
DELAY(50);
DISPLAY(2,3,0x4e,0x4f);
DELAY(50);
DISPLAY(2,4,0x50,0x51);
DELAY(50);
DISPLAY(2,5,0x52,0x53);
DELAY(50);
DISPLAY(2,6,0x54,0x55);
DELAY(50);
DISPLAY(2,7,0x56,0x57);
DELAY(50);
DISPLAY(3,0,0x58,0x59);
DELAY(50);
DISPLAY(3,1,0x5a,0x5b);
DELAY(50);
DISPLAY(3,2,0x5c,0x5d);
DELAY(50);
DISPLAY(3,3,0x5e,0x5f);
DELAY(50);
DISPLAY(3,4,0x60,0x61);
DELAY(50);
DISPLAY(3,5,0x62,0x63);
DELAY(50);
DISPLAY(3,6,0x64,0x65);
DELAY(50);
DISPLAY(3,7,0x66,0x67);
DELAY(50);
DELAY(65000);
DELAY(65000);
DELAY(65000);
CLR_Screen();
DELAY(50);
DISPLAY(1,1,0xba,0xa3); //內(nèi)碼“海”
DELAY(50);
DISPLAY(1,2,0xb5,0xc2); //內(nèi)碼“德”
DELAY(50);
DISPLAY(1,3,0xd7,0xd4); //內(nèi)碼“自”
DELAY(50);
DISPLAY(1,4,0xb6,0xaf); //內(nèi)碼“動(dòng)”
DELAY(50);
DISPLAY(1,5,0xbb,0xaf); //內(nèi)碼“化”
DELAY(50);
DISPLAY(2,2,0xbf,0xaa); //內(nèi)碼“開”
DELAY(50);
DISPLAY(2,3,0xb7,0xa2); //內(nèi)碼“發(fā)”
DELAY(50);
DISPLAY(2,4,0xca,0xd2); //內(nèi)碼“室”
DELAY(65000);
DELAY(65000);
DELAY(65000);
CLR_Screen();
}
}
//-----------------------------------------------------------------------------
// 主芯片初始化
//-----------------------------------------------------------------------------
void SYSCLK_Init (void) //主芯片初始化
{
EA=0; //禁止中斷
XBR1=0x40; //允許交叉開關(guān)
OSCICN=0xc0; //內(nèi)部高頻振蕩的8分頻FOSC/8=24.5/8=3.0625Mhz FSYSCLK
PCA0MD=0x00; //禁止看門狗定時(shí)器
P0=0x00;
P1=0x00;
}
//-----------------------------------------------------------------------------
// 在h行,l列的位置顯示指定漢字或字符,行(0-3),列(0-7)
//-----------------------------------------------------------------------------
void DISPLAY(unsigned char h,unsigned char l,unsigned char LCD_data_H,unsigned char LCD_data_L){
unsigned char code adress[4][8]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f};
_nop_();_nop_();_nop_();
RS=0; //設(shè)定DDRAM地址(80H-9FH)1 AC6 AC5 AC4 AC3 AC2 AC1 AC0
RW=0;
_nop_();_nop_();_nop_();
SEND_Byte (adress[h][l]);
_nop_();_nop_();_nop_();
DELAY(100); //延時(shí)80us
_nop_();_nop_(); // 寫顯示數(shù)據(jù)到RAM,每個(gè)RAM地址都要連續(xù)寫入兩個(gè)字節(jié)的數(shù)據(jù)
RW=0;
_nop_();_nop_();
RS=1;
_nop_();_nop_();
SEND_Byte (LCD_data_H); //發(fā)送顯示數(shù)據(jù)高字節(jié)
_nop_();_nop_();
DELAY(100); //延時(shí)100us
RW=0;
_nop_();_nop_();
RS=1;
_nop_();_nop_();
SEND_Byte (LCD_data_L); //發(fā)送顯示數(shù)據(jù)低字節(jié)
_nop_();_nop_();
DELAY(100); //延時(shí)100us
}
//-----------------------------------------------------------------------------
// LCD初始化
//-----------------------------------------------------------------------------
void LCD_Init (void){
CLR_Screen(); // LCD清屏
_nop_();_nop_();_nop_();
RS=0;
RW=0;
_nop_();_nop_();_nop_();
SEND_Byte (0x06); //光標(biāo)右移,AC自動(dòng)加一,整體顯示不移動(dòng)
_nop_();_nop_();_nop_();
DELAY(100); //延時(shí)80us
_nop_();_nop_();_nop_();
RS=0;
RW=0;
_nop_();_nop_();_nop_();
SEND_Byte (0x0c); //整體顯示ON,光標(biāo)顯示OFF,光標(biāo)位置不反白閃爍
_nop_();_nop_();_nop_();
DELAY(100); //延時(shí)100us
_nop_();_nop_();_nop_();
RS=0;
RW=0;
_nop_();_nop_();_nop_();
SEND_Byte (0x30); //8-BIT 控制接口,基本指令集動(dòng)作
_nop_();_nop_();_nop_();
DELAY(100); //延時(shí)100us
_nop_();_nop_();_nop_();
}
//-----------------------------------------------------------------------------
// LCD清屏
//-----------------------------------------------------------------------------
void CLR_Screen (void){
RW=0;
_nop_();_nop_();
RS=0;
_nop_();_nop_();_nop_();
SEND_Byte (0x01); //發(fā)送清屏指令
_nop_();_nop_();_nop_();
DELAY(2000);
_nop_();_nop_();_nop_();
}
//-----------------------------------------------------------------------------
// 發(fā)送一個(gè)字節(jié)
//-----------------------------------------------------------------------------
void SEND_Byte (unsigned char LCD_Byte){
unsigned char i;
CS=1;
_nop_();_nop_();_nop_();_nop_();
STD=1;
_nop_();_nop_();
for (i=0;i<5;i++){ //發(fā)送同步位字符串
SCLK=0;
_nop_();_nop_();
SCLK=1;
_nop_();_nop_();
}
STD=RW; //發(fā)送RW
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
STD=RS; //發(fā)送RS
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
STD=0; //發(fā)送一個(gè)0
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
i=4; //發(fā)送數(shù)據(jù)高四位
while(i--){
STD=(bit)(LCD_Byte&0x80);
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
LCD_Byte<<=1;
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
}
STD=0; //發(fā)送4個(gè)0
i=4;
for (i=0;i<4;i++){
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
}
_nop_();
_nop_();
i=4; //發(fā)送數(shù)據(jù)低四位
while(i--){
STD=(bit)(LCD_Byte&0x80);
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
LCD_Byte<<=1;
_nop_();_nop_();
SCLK=0;
_nop_();_nop_();
SCLK=1;
_nop_();_nop_();
}
STD=0; // 發(fā)送4個(gè)0
i=4;
for (i=0;i<4;i++){
SCLK=0;
_nop_();
_nop_();
SCLK=1;
_nop_();
_nop_();
}
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
CS=0;
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
//-----------------------------------------------------------------------------
// 延時(shí)COUNT*1us
//-----------------------------------------------------------------------------
void DELAY(unsigned int count) //延時(shí)COUNT*1us
{
unsigned int k,p;
for(k=0; k<count; k++){
for (p=0; p<=4; p++){
_nop_();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -