你应该贴这个给人家看。
- #define SOFTIIC_SCL P1_0
- #define SOFTIIC_SCL_OUT {P1M1|=0x01;P1M0|=0x01;}//P1_0开漏输出
- #define SOFTIIC_SDA P1_1
- #define SOFTIIC_SDA_IN {P1M1|=0x02;P1M0&=~0x02;}//P1_1高阻输入
- #define SOFTIIC_SDA_OUT {P1M1|=0x02;P1M0|=0x02;}//P1_1开漏输出
- #include <STC8HX.h>
- uint32 sys_clk = 24000000;//设置PWM、定时器、串口、EEPROM频率参数
- #include "mylib/TM1650.h"
- #include "lib/delay.h"
- uint8 shi = 23;
- uint8 fen = 59;
- uint8 miao = 50;
- uint8 lj_50ms = 0;
- void diaplay();
- void Timer0Init(void) //2566微秒@24.000MHz
- {
- AUXR &= 0x7f; //定时器时钟12T模式
- TMOD &= 0xf0; //设置定时器模式
- TL0 = 0xf4; //设定定时初值
- TH0 = 0xeb; //设定定时初值
- }
- /*描述该功能...
- */
- void diaplay(){
- TM1650_displayBit(fen % 10,1,0);
- TM1650_displayBit(fen / 10,2,0);
- TM1650_displayBit(shi % 10,3,1);
- TM1650_displayBit(shi / 10,4,0);
- }
- void T_IRQ0(void) interrupt 1 using 1{
- lj_50ms--;if(lj_50ms == 0){
- miao++;if(miao >= 60){
- fen++;miao = 0;
- if(fen >= 60){
- shi++;miao = 0;
- fen = 0;
- if(shi >= 24){
- delay(160000);
- miao = 0;
- fen = 0;
- shi = 0;
- }
- }
- }
- }
- }
- void setup()
- {
- TM1650_Init();//TM1650初始化
- Timer0Init();
- EA = 1; // 控制总中断
- ET0 = 1; // 控制定时器中断
- TR0 = 1;// 定时器0开始计时
- P3M1&=~0x08;P3M0|=0x08;//推挽输出
- P3M1&=~0x04;P3M0|=0x04;//推挽输出
- P3M1&=~0x80;P3M0|=0x80;//推挽输出
- }
- void loop()
- {
- diaplay();
- if(P3_2 == 0){
- if(fen <= 58){
- fen = fen + 1;
- delay(150);
- }
- else{
- fen = 0;
- }
- }
- if(P3_3 == 0){
- if(shi <= 23){
- shi = shi + 1;
- delay(150);
- }
- else{
- shi = 0;
- }
- }
- if((P3_3 == 0) && (P3_2 == 0)){
- miao = 0;
- }
- }
- void main(void)
- {
- setup();
- while(1){
- loop();
- }
- }
复制代码
为什么定时器是设置成这样?
2566微秒@24.000MHz
|