給你一個測試程序參考
- #include <STC89C5xRC.H>
- //宏定義新LCD的操作命令
- #define ComMode 0x52 //4COM,1/3bias 1000 0101 0010
- //#define ComMode 0x50 //4COM,1/2bias 1000 0101 0000
- #define RCosc 0x30 //內(nèi)部RC振蕩器(上電默認)1000 0011 0000
- #define LCD_on 0x06 //打開LCD顯示 偏壓發(fā)生器1000 0000 0110
- #define LCD_off 0x04 //關(guān)閉LCD顯示(上電默認)
- #define Sys_en 0x02 //系統(tǒng)振蕩器開 1000 0000 0010
- #define Ctrl_cmd 0x80 //寫控制命令 1000
- #define Data_cmd 0xa0 //寫數(shù)據(jù)命令 1010
- // 端口聲明
- sbit DIPIN=P3^7;
- sbit CLKPIN=P3^6;
- sbit CSPIN=P3^5;
- /**-------------------------------------------------------------------------
- Name: SendBit_1621(送數(shù)據(jù)程序)
- ---------------------------------------------------------------------------*/
- void SendBit_1621(unsigned char sdata,unsigned char cnt) //sdata 的高cnt 位寫入HT1621,高位在前
- {
- unsigned char i;
- for(i=0;i<cnt;i++)
- {
- CLKPIN=0;
- if(sdata&0x80)
- DIPIN=1;
- else DIPIN=0;
- CLKPIN=1;
- sdata<<=1;
- }
- }
- /*-------------------------------------------------------------------------
- Name: SendCmd(送命令)
- 寫入標志碼"100"和9位comma命令,由于沒有使用到更改時鐘輸出等命令
- 為了編程方便直接將command 的最高位寫"0"
- ---------------------------------------------------------------------------*/
- void SendCmd_1621(unsigned char command)//寫命令
- {//3位標志碼 + 9位命令,共12位
- CSPIN=0; //執(zhí)行一個下降沿
- SendBit_1621(0x80,4); //寫入標志碼"100"和9位comma命令的最高1位共4位
- SendBit_1621(command,8); //寫入9位comma命令的后8位,組成1000 xxxx xxxx
- CSPIN=1;//送數(shù)完成后置高電平
- }
- /**-------------------------------------------------------------------------
- Name: Write_1621(送命令和數(shù)據(jù)程序)
- 寫入標志碼"101"和6位addr地址碼和8位sdata顯示數(shù)據(jù)。
- ---------------------------------------------------------------------------*/
- void Write_1621(unsigned char addr,unsigned char sdata,unsigned char len)//寫數(shù)據(jù)
- {//3位標志碼 + 6位寫數(shù)據(jù)命令 + len(4/8)位數(shù)據(jù),共13/17位
- addr<<=2;//高6位有效
- CSPIN=0; //執(zhí)行一個下降沿
- SendBit_1621(0xa0,3); //寫入標志碼"101" 寫數(shù)據(jù)命令101
- SendBit_1621(addr,6); //寫入addr 的高6位 寫數(shù)據(jù)命令xxxx xx
- SendBit_1621(sdata,len); //寫入8/4位 sdata數(shù)據(jù) len=8/4
- CSPIN=1;//送數(shù)完成后置高電平
- }
- /**-------------------------------------------------------------------------
- Name: Init_1621(初始化1621)
- -------------------------------------------------------------------------*/
- void LCD_Init() //初始化
- {//程序輸入100 0+8=9位命令
- SendCmd_1621(Sys_en);//Sys_en 0x02 系統(tǒng)振蕩器開 100 0 0000 0010
- SendCmd_1621(RCosc); //RCosc 0x30 內(nèi)部RC振蕩器(上電默認) 100 0 0011 0000
- SendCmd_1621(ComMode);//4COM,1/3bias 100 0 0101 0020
- SendCmd_1621(LCD_on);//LCD_on 0x06 打開LCD顯示 偏壓發(fā)生器100 0 0000 0110
- }
- /*-------------------------------------------------------------------------
- Name: lcdwd1(點亮1621全部Seg)
- -------------------------------------------------------------------------*/
- void lcdwd1(unsigned char num)
- {
- unsigned char i;
- unsigned char addr=0;//寄存器起始地址0x00
- for(i=0;i<num;i++)//num有效地址數(shù)
- {
- Write_1621(addr,0xff,8);//addr為地址,0xff為數(shù)據(jù),8為8位數(shù)據(jù)
- addr+=2;//順延2個4位地址碼
- }
- }
- void main()
- {
- LCD_Init();
- while(1)
- {
- lcdwd1(16);
- }
- }
復(fù)制代碼
|