数码管用的是共阴数码管,单片机STC11F04E,数码管一直没有任何显示,调试了一天,没进展,求神坛指点。
现在要求不高,只要数码管有一点显示就行啊
下载界面.png (83.06 KB, 下载次数: 0)
下载附件
2013-2-7 19:37 上传
- #include <intrins.h>
- #include <STC11F04E.H>
- #include <stdio.h>
- #define SYSTEM_CLK 11520000
- void uart_init(unsigned int baud) {
- SCON = 0x50;
- TMOD |= 0x20;
- TH1 = 256 - SYSTEM_CLK / baud / 384;
- TR1 = 1;
- TI = 1;
- }
- void Delay500ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- i = 22;
- j = 3;
- k = 227;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void _delay_us(unsigned char i) //@11.0592MHz
- {
- while(i--)
- {
- _nop_();
- }
- }
- sbit STB = P3^3;
- sbit CLK = P3^4;
- sbit DIO = P3^5;
- sbit led1 = P1^6;
- sbit led2 = P1^7;
- #define DIO_high do{DIO=1;}while(0)
- #define DIO_low do{DIO=0;}while(0)
- #define CLK_high do{CLK=1;}while(0)
- #define CLK_low do{CLK=0;}while(0)
- #define STB_high do{STB=1;}while(0)
- #define STB_low do{STB=0;}while(0)
- unsigned char tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
- void TM1638_Write(unsigned char DATA) //写数据函数
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- CLK_low;
- if(DATA&0X01)
- DIO_high;
- else
- DIO_low;
- DATA>>=1;
- CLK_high;
- _delay_us(1);
- }
- }
- void Write_COM(unsigned char cmd) //发送命令字
- {
- STB_low;
- TM1638_Write(cmd);
- STB_high;
- _delay_us(1);
- }
- void init_TM1638(void)
- {
- unsigned char i;
- Write_COM(0x8F);//亮度
- Write_COM(0x40);
- STB_low;
- TM1638_Write(0xc0);
- for(i=0;i<16;i++)
- TM1638_Write(0x00);
- STB_high;
- }
- int main(void)
- {
- unsigned int i=0,j=0;
- unsigned char flag=0;
- init_TM1638();
- uart_init(9600);
- Delay500ms();
- while(1)
- {
- for(i=0; i<8; i++)
- {
- printf("i=%2d; this is a test.
",i);
- Write_COM(0x8F);//亮度
- Write_COM(0x40);
- STB_low;
- TM1638_Write(0xc0);
- for(j=0;j<16;j++)
- {
- TM1638_Write(i);
- }
- STB_high;
- Delay500ms();
-
- }
- }
- }
复制代码
linecap.gif (28.86 KB, 下载次数: 0)
下载附件
2013-2-7 20:59 上传
一周热门 更多>