动态数码管循环显示设计C语言及汇编代码(HUBU)

动态数码管循环显示设计(HUBU电信)

实验任务(两个实验):
1.单只数码管循环显示0-9;
2.8只数码管滚动显示单个数字。

第一题实验电路如下:
动态数码管循环显示设计C语言及汇编代码(HUBU)_第1张图片
此题我写的代码比较笨,同学们可以进行TAB列表操作进行修改,详见下方C语言
本文档仅供学习参考之用,作业请勿抄袭

第一题 汇编代码:

ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:     
MOV	TMOD,#01H		  
MOV   TL0,#10H   		  
MOV	TH0,#00H		  
SETB  TR0		  
MOV   R0,#0FEH		  
MOV   A ,R0          
LOOP0:    JBC	TF0,PTF0 ;      既使用了查询方式计时,也使用了子程序计时		  SJMP  LOOP0
PTF0:     MOV   A,#3fH		  
MOV   p0,A         		  
ACALL  DELAY		  
ACALL  DELAY		  
ACALL  DELAY		  
MOV	TL0,#10H		  
MOV   TH0,#000H		 
LOOP1:    JBC	TF0,PTF1;        循环9次,最后进行一个大循环		 
SJMP  LOOP1
PTF1:     MOV   A,#06H		  
MOV   p0,A		  
ACALL  DELAY		 
ACALL  DELAY		  
ACALL  DELAY		  
MOV   TL0,#10H		  
MOV   TH0,#000H
LOOP2:    JBC	
TF0,PTF2		  
SJMP  LOOP2
PTF2:     MOV   A,#5bH		  
MOV   p0,A		  
ACALL  DELAY		 
ACALL  DELAY		  
ACALL  DELAY		  
MOV	TL0,#10H		  
MOV   TH0,#000H
LOOP3:    JBC	TF0,PTF3		  
SJMP  LOOP3PTF3:     
MOV   A,#4fH		 
 MOV   p0,A		  
 ACALL  DELAY		 
 ACALL  DELAY		 
 ACALL  DELAY		  
 MOV	TL0,#10H		 
 MOV   TH0,#000H
 LOOP4:  JBC	TF0,PTF4		  
 SJMP  LOOP4PTF4:     
 MOV   A,#66H		  
 MOV   p0,A		  
 ACALL  DELAY		  
 ACALL  DELAY		  
 ACALL  DELAY		  
 MOV	TL0,#10H		  
 MOV   TH0,#000H
 LOOP5:    JBC	TF0,PTF5		  
 SJMP  LOOP5
 PTF5:     MOV   A,#6dH		  
 MOV   p0,A		 
 ACALL  DELAY		 
 ACALL  DELAY		  
 ACALL  DELAY		  
 MOV	TL0,#10H		  
 MOV   TH0,#000H
 LOOP6:    JBC	TF0,PTF6		  
 SJMP  LOOP6
 PTF6:   MOV   A,#7dH		 
 MOV   p0,A		 
 ACALL  DELAY		  
 ACALL  DELAY		 
 ACALL  DELAY		  
 MOV	TL0,#10H		  
 MOV   TH0,#000H	  
 LOOP7:    JBC	TF0,PTF7		  
 SJMP  LOOP7
 PTF7:     MOV   A,#07H		  
 MOV   p0,A		 
 ACALL  DELAY		  
 ACALL  DELAY		  
 ACALL  DELAY		  
MOV	TL0,#10H		  
MOV   TH0,#000H
LOOP8:    JBC	TF0,PTF8		  
SJMP  LOOP8
PTF8:     MOV   A,#7fH		  
MOV   p0,A		  
ACALL  DELAY		  
ACALL  DELAY		  
ACALL  DELAY		  
MOV	TL0,#10H		  
MOV   TH0,#000H  
LOOP9:    JBC	TF0,PTF9		  
SJMP  LOOP9
PTF9:     MOV   A,#6fH		  
MOV   p0,A		  
ACALL  DELAY		  
ACALL  DELAY		  
ACALL  DELAY		  
MOV	TL0,#10H		  
MOV   TH0,#000H		  
AJMP  LOOP0 
DELAY: MOV R7,#250 
D1: MOV R6,#250 
D2: DJNZ R6,D2 
DJNZ R7,D1
RET
END

第一题c语言代码:

#include"reg51.h"
void delay (void) {	
TMOD=0x01;				
TR0=1;			 			
TH0=(65536)/256;	        //查询方式计时		
TL0=(65536)%256;		 
while (! TF0)		 
{}			
TF0=0;				
}
void main(){	
int i=0;
int table [10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //定义数码表while(1){
for(i=0;i<10;i++){
P0 = table[i];
delay();
delay();                           //使用延时程序delay();
}
}
}

第二题电路图:
动态数码管循环显示设计C语言及汇编代码(HUBU)_第2张图片
第二题 汇编代码:

ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:  MOV TMOD,#01H    
MOV   TL0,#00H    
MOV   TH0,#00H    
SETB  TR0   
MOV   R0,#0FEH    
MOV   A ,R0
LOOP0:    JBC TF0,PTF0;     既使用了查询方式计时,也使用了子程序计时    
SJMP  LOOP0  
PTF0:     MOV   A,#0c0H           
MOV   p0,A    
MOV   p2,#01H   
ACALL  DELAY    
ACALL  DELAY    
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H    
LOOP1:    JBC TF0,PTF1;            循环9次,最后进行一个大循环    SJMP  LOOP1
PTF1:     MOV   A,#0f9H    
MOV   p0,A    
MOV   p2,#02H    
ACALL  DELAY    
ACALL  DELAY    
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP2:    JBC TF0,PTF2    
SJMP  LOOP2
PTF2:    MOV   A,#0a4H    
MOV   p0,A    
MOV   p2,#04H    
ACALL  DELAY    
ACALL  DELAY   
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP3:    JBC TF0,PTF3    
SJMP  LOOP3
PTF3:     MOV   A,#0b0H            
MOV   p2,#08H    
MOV   p0,A     
ACALL  DELAY    
ACALL  DELAY   
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP4:    JBC TF0,PTF4    
SJMP  LOOP4
PTF4:     MOV   A,#99H    
MOV   p0,A     
MOV   p2,#10H     
ACALL  DELAY     
ACALL  DELAY     
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP5:    JBC TF0,PTF5    
SJMP  LOOP5
PTF5:     MOV   A,#92H    
MOV   p0,A     
MOV   p2,#20H     
ACALL  DELAY     
ACALL  DELAY     
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP6:    JBC TF0,PTF6    
SJMP  LOOP6
PTF6:     MOV   A,#82H    
MOV   p0,A     
MOV   p2,#40H     
ACALL  DELAY    
ACALL  DELAY     
ACALL  DELAY    
MOV    TL0,#00H    
MOV   TH0,#00H  
LOOP7:    JBC TF0,PTF7    
SJMP  LOOP7
PTF7:     MOV   A,#0f8H    
MOV   p0,A     
MOV   p2,#80H     
ACALL  DELAY     
ACALL  DELAY     
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H
LOOP8:    JBC TF0,PTF8    
SJMP  LOOP8
PTF8:     MOV   A,#80H    
MOV   p0,A     
MOV   p2,#01H     
ACALL  DELAY     
ACALL  DELAY     
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H  
LOOP9:    JBC TF0,PTF9    
SJMP  LOOP9
PTF9:     MOV   A,#90H    
MOV   p0,A     
MOV   p2,#02H     
ACALL  DELAY     
ACALL  DELAY     
ACALL  DELAY    
MOV TL0,#00H    
MOV   TH0,#00H    
AJMP  LOOP0   
DELAY:       MOV R7,#250 
D1: MOV R6,#250 
D2: DJNZ R6,D2 
DJNZ R7,D1
RET
END

第二题C语言代码:

#include
void delay (void) {	
TMOD=0x01;				
TR0=1;			 			
TH0=(65536)/256;			
TL0=(65536)%256;              //查询方式计时		 
while (! TF0)		
{}			
TF0=0;				
}
void main(){	
int i=0;	
int j=0x80;
int table [10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};  //定义数码表
int weima[10] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};         //定义位码表
while(1){
for(i=0;i<10;i++){
P0 = table[i];
P2 = weima[i];
delay();
delay();
delay();            //延时程序调用,多次调用则会增长延时时间
delay();
delay();
}
}
}

实验结果:
第一题实验结果:
动态数码管循环显示设计C语言及汇编代码(HUBU)_第3张图片
第二题实验结果:
动态数码管循环显示设计C语言及汇编代码(HUBU)_第4张图片

你可能感兴趣的:(单片机)