|
- /*****************************************************************************
- *版權(quán)信息:
- *文 件 名:
- *當(dāng)前版本:V1.0
- *MCU 型號(hào):STC12C5608AD
- *開(kāi)發(fā)環(huán)境:Keil uVision4
- *晶震頻率:11.0592MHZ
- *完成日期:2013-07-29
- *程序功能:1.上電8段4位共陰數(shù)碼管顯示1、2、3、4.
- 2.按下K11與DIG1,K12與DIG2 ,K13與DIG3之間的按鍵,數(shù)碼管第一位分別顯示5、6、7。
- *免責(zé)聲明:
- ********************************************************************************/
- #include<reg52.h> //MCU頭文件
- #include<intrins.h> //包含nop指令頭文件
- #define uint unsigned int //數(shù)據(jù)類型宏定義
- #define uchar unsigned char //數(shù)據(jù)類型宏定義
- #define nop _nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); //宏定義
- /********************定義控制端口**********************/
- sbit SCL=P3^3; //時(shí)鐘線
- sbit SDA=P3^2; //數(shù)據(jù)線
- uchar keya; //定義讀出按鍵返回值
- /*************1ms延時(shí)*晶振11.0592M********************/
- void delay(uint n)
- {
- uint i;
- while(n--)
- for(i=0;i<550;i++);
- }
- /**************共陰數(shù)碼管顯示0-F**********************/
- uchar display[]={0xFF,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E}; //共陰極字段碼
- /************ START信號(hào)*******************************/
- void FZH110_START()
- {
- SCL=1;
- SDA=1;
- nop;
- SDA=0;
- nop;
- SCL=0;
- }
- /******************** STOP信號(hào)************************/
- void FZH110_STOP()
- {
- SDA=0;
- nop;
- SCL=1;
- nop;
- SDA=1;
- nop;
- SCL=0;
- SDA=0;
- }
- /****************寫(xiě)1個(gè)字節(jié)給FZH110********************/
- void write_8bit( uchar dat)
- {
- uchar i;
- SCL=0;
- for(i=0;i<8;i++)
- {
- if(dat&0x80)
- {
- SDA=1;
- nop;
- nop;
- SCL=1;
- nop;
- nop;
- nop;
- nop;
- nop;
- SCL=0;
- }
- else
- {
- SDA=0;
- nop;
- nop;
- SCL=1;
- nop;
- nop;
- nop;
- nop;
- nop;
- SCL=0;
- }
- dat<<=1;
- }
- SDA=1; //ACK信號(hào)
- nop;
- nop;
- nop;
- nop;
- SCL=1;
- nop;
- nop;
- nop;
- nop;
- nop;
- SCL=0;
- nop;
- nop;
- }
- /**********************讀8bit**************************/
- uchar read_8bit()
- {
- uchar dat,i;
- SDA=1;
- dat=0;
- for(i=0;i<8;i++)
- {
- SCL=1; //時(shí)鐘上沿
- nop;
- nop;
- nop;
- dat<<=1;
- if(SDA)
- dat++;
- SCL=0;
- nop;
- nop;
- nop;
- nop;
- }
- SDA=0; //ACK信號(hào)
- nop;
- nop;
- nop;
- SCL=1;
- nop;
- nop;
- nop;
- nop;
- SCL=0;
- nop;
-
- return dat ;
- }
- /*******************讀按鍵命令************************/
- uchar FZH110_read()
- {
- uchar key;
- FZH110_START();
- write_8bit(0x4F);//讀按鍵指令
- key=read_8bit();
- FZH110_STOP();
- return key;
- }
- /*****************發(fā)送命令信號(hào)***********************/
- void FZH110_send(uchar date1,uchar date2)
- {
- FZH110_START();
- write_8bit(date1);
- write_8bit(date2);
- FZH110_STOP();
- }
- /*****************顯示函數(shù)***********************/
- void disp_close()
- {
- FZH110_send(0x48,0x01); // 開(kāi)啟顯示模式:8段顯示,1級(jí)亮度
- FZH110_send(0X68,display[1]); //GID1
- FZH110_send(0X6A,display[0]); //GID2
- FZH110_send(0X6C,display[0]); //GID3
- FZH110_send(0X6E,display[0]); //GID4
- }
- /**************主函數(shù)**************************/
- void main(void)
- {
- //上電顯示1、2、3、4
- delay(10);
-
- while(1)
- {
- disp();
- }
- }
復(fù)制代碼 最近做了個(gè)數(shù)碼管驅(qū)動(dòng)的程序,但發(fā)現(xiàn)廠家給的程序竟然不行!改了很多地方?jīng)]有效果,狀態(tài)為:四位數(shù)碼管只能顯示同一個(gè)數(shù)字,顯示了不同的就會(huì)花屏,而且亮度怎么改都沒(méi)變化,請(qǐng)求各位大佬幫忙找找錯(cuò)誤的地方!
|
|