|
忘了贴代码。
- #include <STC15F2K60S2.H>
- //#include "TM1639.h"
- #include <intrins.h>
- sbit TM1639_DIO = P1^4;
- sbit TM1639_CLK = P1^5;
- sbit TM1639_STB = P1^6;
- // 共阴数码管段码表(0~9)
- const unsigned char SegCode[] =
- {
- 0x3F, // 0
- 0x06, // 1
- 0x5B, // 2
- 0x4F, // 3
- 0x66, // 4
- 0x6D, // 5
- 0x7D, // 6
- 0x07, // 7
- 0x7F, // 8
- 0x6F // 9
- };
- // 向TM1639写入一个字节
- void TM1639_WriteByte(unsigned char ddd)
- {
- unsigned char i;
-
- for (i = 0; i < 8; i++)
- {
- TM1639_CLK = 0;
- TM1639_DIO = (ddd & 0x01) ? 1 : 0;
- _nop_();//***********
- TM1639_CLK = 1;
- ddd >>= 1;
- }
- }
- // 发送命令
- void TM1639_SendCommand(unsigned char cmd)
- {
- TM1639_STB = 0;
- TM1639_WriteByte(cmd);
- TM1639_STB = 1;
- }
- // 显示数字“1”和“2”
- void Display_12()
- {
- TM1639_STB = 0;
- TM1639_WriteByte(0x40); // 地址自动增加模式
- TM1639_STB = 1;
- TM1639_STB = 0;
- TM1639_WriteByte(0xC0); // 起始地址为0xC0(GRID1)
- TM1639_WriteByte(SegCode[1]); // 第一位显示“1”
- TM1639_WriteByte(SegCode[2]); // 第二位显示“2”
- TM1639_STB = 1;
- }
- void main()
- {
- TM1639_SendCommand(0x8f); // 设置亮度(0x88~0x8F,最亮为0x8F)
- while(1)
- {
- Display_12(); // 持续显示“12”
- }
- }
复制代码
|
|