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