小弟编制一个程序功能是:利用定时器0和数显芯片做一个时,分,秒显示(6个数码管)
汇编程序已经编制出来了 可是用C语言却不能实现
汇编程序:
EN BIT P2.7
DOUT BIT P2.6
CLK BIT P2.5
DISPBUF EQU 20H
MSCNT EQU 30H
ORG 0000H
AJMP MAIN
ORG 000BH
LJMP TC0INT
ORG 0035H
;**************************************
;主程序
;**************************************
MAIN: MOV SP,#60H
MOV R7,#06H
MOV R0,#DISPBUF+1
LOOPCLR: MOV @R0,#00H
INC R0
DJNZ R7,LOOPCLR
MOV TMOD,#01H
MOV TH0,#0BH
MOV TL0,#0DCH
SETB EA
SETB ET0
SETB TR0
MOV MSCNT,#10H
LCALL SETXIAO
LCALL TSLED
SJMP $
;**************************************
;中断服务程序
;**************************************
TC0INT: PUSH PSW
PUSH ACC
CLR RS1
SETB RS0
MOV TH0,#0BH
MOV TL0,#0DCH
MOV A,MSCNT
DEC A
MOV MSCNT,A
JNZ GOTO_RET
MOV MSCNT,#10H
;秒的调整处理
MOV R0,#DISPBUF+2
LCALL DAADL
CJNE R2,#60H,TSLED_LOOP
LCALL CLR0
;分的调整处理
MOV R0,#DISPBUF+4
LCALL DAADL
CJNE R2,#60H,TSLED_LOOP
LCALL CLR0
;时的调整处理
MOV R0,#DISPBUF+6
LCALL DAADL
CJNE R2,#24H,TSLED_LOOP
LCALL CLR0
TSLED_LOOP: LCALL TSLED
GOTO_RET: POP ACC
POP PSW
RETI
;****************************************
;调整子程序
;****************************************
DAADL: ;合并
MOV A,@R0
SWAP A
DEC R0
ORL A,@R0
INC A
DA A
MOV R2,A
;拆分
ANL A,#0FH
MOV @R0,A
MOV A,R2
ANL A,#0F0H
SWAP A
INC R0
MOV @R0,A
RET
;*****************************************
;缓冲清0子程序
;*****************************************
CLR0: CLR A
MOV @R0,A
DEC R0
MOV @R0,A
RET
;*****************************************
;DTLED-6小数位、ID识别码、蜂鸣器设置子程序
;*****************************************
SETXIAO: MOV R0,#DISPBUF
MOV @R0,#00H
MOV R0,#DISPBUF+7
MOV @R0,#01H
MOV R0,#DISPBUF+8
MOV @R0,#00H
RET
;**************************************
;DTLED-6送数码管显示子程序
;**************************************
TSLED: CLR CLK
CLR EN
LCALL DELAY_200US
MOV R0,#DISPBUF
MOV R2,#00H
MOV R3,#00H
LEDBYTE_LOOP: MOV A,@R0
SWAP A
LEDBIT_LOOP: SETB CLK
RLC A
MOV DOUT,C
CLR CLK
LCALL DELAY_10US
INC R3
CJNE R3,#04H,LEDBIT_LOOP
MOV R3,#00H
INC R2
INC R0
CJNE R2,#09H,LEDBYTE_LOOP
SETB EN
RET
;**************************************
;200US延时子程序
;**************************************
DELAY_200US: MOV R4,#98
DJNZ R4,$
NOP
RET
;**************************************
;10US延时子程序
;**************************************
DELAY_10US: MOV R4,#3
DJNZ R4,$
NOP
RET
;***************************************
;程序结束
;***************************************
END
自己试编的C语言如下:请高手看看问题出在哪里?
#include "at89x52.h"
#include "stdio.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define nop _nop_();
sbit en=P2^7;
sbit dout=P2^6;
sbit clk=P2^5;
uchar dispbuf【9】;
uchar clocktime【4】;
uint mscnt;
uint i;
void delay (unsigned int value)
{
while (value!=0)
value--;
}
void setxiao(void);
v
给个AVR的,效果一样
#include <iom8v.h>
#include <macros.h>
//#include "timer.h"
//#include "main.h"
#define s3 bit7
#define s3_on PORTD &= ~s3
#define s3_off PORTD |= s3
#define s2 bit0
#define s2_on PORTB &= ~s2
#define s2_off PORTB |= s2
#define s0 bit1
#define s0_on PORTB &= ~s0
#define s0_off PORTB |= s0
#define s1 bit2
#define s1_on PORTB &= ~s1
#define s1_off PORTB |= s1
const unsigned char led_table[]={0x00,0x39,0x24,0x30,0x19,0x12,0x02,0x38,0x00,0x10,0x3f};
unsigned char led[4];
unsigned char led_on=0;
//TIMER2 initialisation - prescale:64
// WGM: Normal
// desired value: 2mSec
// actual value: 2.000mSec (0.0%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT2 = 0x83; //setup
OCR2 = 0x7D;
TCCR2 = 0x04; //start
}
#pragma interrupt_handler timer2_ovf_isr:5
void timer2_ovf_isr(void)
{
TCNT2 = 0x83; //reload counter value
switch (led_on)
{
case 0:
s3_off;
s0_on;
break;
case 1:
s0_off;
s1_on;
break;
case 2:
s1_off;
s2_on;
break;
case 3:
s2_off;
s3_on;
break;
}
PORTC=led_table[led[led_on]];
led_on++;
if (led_on > 3) led_on=0;
{hour,minute,second calculation could be here}
}
void main(void)
{//n=<9
for(;;) {
led[0]=n.....led[3]=n-3;
}
}