单片机复习材料(6)
发布时间:2021-06-05
发布时间:2021-06-05
模块1:
# include<reg51.h> main(){ delay4ms() # define uchar unsigned char uchar i; P1_1=1; sbit P1_1=p1^1; for(;;){ delay4ms(); void delay4ms(void); P1_1=0; }}
模块2:
# include<reg51.h> void delay4ms(void){ Delay1ms(2); # define uchar unsigned char P1_0=0; } sbit P1_0=p1^0; delay1ms(2); delay1ms(uchar x); P1_0=1;
模块3:
PUBLIC _DELAY1MS NOP DE SEGMENT DODE DJNZ R1,LOP1 RSEG DE DJNZ R7,DELA _DELAY1MS: NOP EXIT: RET DELA: MOV R1,#0F8H END LOP1: NOP
上例可见,汇编语言程序从R7中获取参数(x=2)。
[4-14] 在汇编程序中比较两数大小,将大数放到指定的存储区,由C程序的主调函数取出。 模块1:C语言程序
#define uchar unsigned char c=0x30; void max (uchar a , uchar b); max(a,b); main(){ d=*c; uchar a=5,b=35,*c , d ; } 模块2:汇编语言程序 PUBLIC _MAX CJNE A,30H ,TAG1 DE SEGMENT CODE TAG1: JC EXIT RSEG DE MOV 30H,R7 MAX: MOV A , R7 EXIT: RET MOV 30H ,R5 END 4-15 A/D采用查询方式采样50个数据(A/D地址位7FF8H),讲其求平均并送数码管显示。 #include <reg51.h>
dis[1]=total%10; P1=0xf8; #define uint unsigned int
dis[2]=total/10; while(1){ #define uchar unsigned char
P3=0x01; total =1; extern void callasm(uchar);
for(m=0;m<50;m++){ callasm (buf); exern void dayl(uint);
for(i=0;i<=3;i++){ for (i=50;i>0;i--) void main (void)
P1=tab[dis[i]]; total +=buf[i-1]; {
day1(50); total=total/50; uint i,j,m,total =0;
P3<<=1; dis[0]=total%10; uchar idata buf[50],dis[3];
}}}} total =total/10; uchar code tab[16]={0x3f,0x06,0x5b,0x4f,0x66,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};