|
合泰杯比賽筆記
#include "HT66F489.h"
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
/*12864端口定義*/
#define LCD_data _pa //數(shù)據(jù)口
#define LCD_RS _pd5 //寄存器選擇輸入
#define LCD_RW _pd4 //液晶讀/寫(xiě)控制
#define LCD_EN _pd3 //液晶使能控制
#define LCD_PSB _pd2 //串/并方式控制
const unsigned char dis1[] = {"xxxxx"};
const unsigned char dis2[] = {"xxxxx"};
const unsigned char dis3[] = {"xxxxx"};
const unsigned char dis4[] = {"xxxxx"};
#define delayNOP(); {GCC_NOP();GCC_NOP();GCC_NOP();GCC_NOP
();};
void lcd_pos(uchar X,uchar Y); //確定顯示位置
/************************************************************
*******/
/*
*/
/* 延時(shí)函數(shù)
*/
/*
*/
/************************************************************
*******/
void delay(int ms)
{
while(ms--)
{
uchar i;
for(i=0;i<250;i++)
{
GCC_NOP();
GCC_NOP();
GCC_NOP();
GCC_NOP();
}
}
}
/************************************************************
*******/
/*
*/
/*檢查L(zhǎng)CD忙狀態(tài)
*/
/*lcd_busy為1時(shí),忙,等待。lcd-busy為0時(shí),閑,可寫(xiě)指令與數(shù)據(jù)。
*/
/*
*/
/************************************************************
*******/
int lcd_busy()
{
int result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delayNOP();
delayNOP();
result = (bit)(_pa&0x80);
LCD_EN = 0;
return(result);
}
/************************************************************
*******/
/*
*/
/*寫(xiě)指令數(shù)據(jù)到LCD
*/
/*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。
*/
/*
*/
/************************************************************
*******/
void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
GCC_NOP();
GCC_NOP();
GCC_NOP();
_pa = cmd;
delayNOP();
delayNOP();
LCD_EN = 1;
delayNOP();
delayNOP();
LCD_EN = 0;
}
/************************************************************
*******/
/*
*/
/*寫(xiě)顯示數(shù)據(jù)到LCD
*/
/*RS=H,RW=L,E=高脈沖,D0-D7=數(shù)據(jù)。
*/
/*
*/
/************************************************************
*******/
void lcd_wdat(uchar dat)
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
_pa = dat;
delayNOP();
delayNOP();
LCD_EN = 1;
delayNOP();
delayNOP();
LCD_EN = 0;
}
/************************************************************
*******/
/*
*/
/* LCD初始化設(shè)定
*/
/*
*/
/************************************************************
*******/
void lcd_init()
{
LCD_PSB = 1; //并口方式
lcd_wcmd(0x34); //擴(kuò)充指令操作
delay(5);
lcd_wcmd(0x30); //基本指令操作
delay(5);
lcd_wcmd(0x0C); //顯示開(kāi),關(guān)光標(biāo)
delay(5);
lcd_wcmd(0x01); //清除LCD的顯示內(nèi)容
delay(5);
}
/*********************************************************/
/*
*/
/* 主程序
*/
/* */
/*********************************************************/
void main()
{
uchar i;
_wdtc=0xa8;//關(guān)閉看門(mén)狗
_pdpu=0xff;//設(shè)置上拉電阻
_papu=0xff;
_pac=0;//輸出
_pdc=0;
delay(10); //延時(shí)
lcd_init(); //初始化LCD
lcd_pos(0,0); //設(shè)置顯示位置為第一行的第1個(gè)字
符
i = 0;
delay(100);
while(dis1[i] != '\0')
{ //顯示字符
lcd_wdat(dis1[i]);
i++;
}
delay(200);
lcd_pos(1,0); //設(shè)置顯示位置為第二行的第1個(gè)字
符
i = 0;
while(dis2[i] != '\0')
{
lcd_wdat(dis2[i]); //顯示字符
i++;
}
delay(200);
lcd_pos(2,0); //設(shè)置顯示位置為第三行的第
1個(gè)字符
i = 0;
while(dis3[i] != '\0')
{
lcd_wdat(dis3[i]); //顯示字符
i++;
}
delay(200);
lcd_pos(3,0); //設(shè)置顯示位置為第四行的第
1個(gè)字符
i = 0;
while(dis4[i] != '\0')
{
lcd_wdat(dis4[i]); //顯示字符
i++;
}
while(1);
}
/*********************************************************/
/* */
/* 設(shè)定顯示位置 */
/* */
/*********************************************************/
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 ;
lcd_wcmd(pos); //顯示地址
}
|
|