while(1)执行ad0804仅能转换一次

while(1)执行ad0804仅能转换一次,第1张

rd=1

rd=0

m=P1

是不是

rd=1

m=P1

rd=0

可以先检查显示函数是否正常。让显示函数显示三个不同的数,就可以确定它是否正常工作。

以前做过一款51的板子,正好上面有0804的部分

数码管显示部分就不要我上传图了吧,都是一个样子的

测试程序

#include<reg52.h>

#include<intrins.h>

#define uchar unsigned char

#define uint  unsigned  int

sbit cs=P3^4

sbit wr=P3^6

sbit rd=P3^7

sbit aa=P2^0

sbit bb=P2^1

sbit cc=P2^2

sbit LE1=P2^7

uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,

0x6d,0x7d,0x07,0x7f,0x6f}

void init()

void ad_start()

uchar  ad_read()

void display(uchar bai,uchar shi,uchar ge )

void delay(uint t)  //延时程序

{

uint i

for(t>0t--)

for(i=110i>0i--)

}

void main()

{

uchar adout,a1,a2,a3

init()

while(1)

{

ad_start()

delay(10)

adout=ad_read()

P1=ad_read()

a1=adout/100

a2=adout%100/10

a3=adout%100%10

display(a1,a2,a3)

}

}

void init()

{

P1=0xff

P2=0xff

P3=0xff

}

void ad_start()   //start convertion

{

cs=0

_nop_()

wr=0

_nop_()

wr=1

_nop_()

cs=1

}

uchar  ad_read()

{

uchar temp

P1=0xff

cs=0

_nop_()

rd=0

_nop_()

temp=P1

_nop_()

rd=1

_nop_()

cs=1

wr=0

return(temp)

}

void display(uchar bai,uchar shi,uchar ge )

{

LE1=1//选通138

aa=0

bb=0

cc=0

P0=table[bai]

delay(1)

aa=1

bb=0

cc=0

P0=table[shi]

delay(1)

aa=0

bb=1

cc=0

P0=table[ge]

delay(1)

P0=0   //关闭显示

LE1=0

}

你好!

你的这个情况,要一步步去调试:

1、先把数码管程序看好

2、检查0804 的硬件部分

3、0804硬件没问题,再看程序

4、可以帮你调试程序,但是需要全部的原理图


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7785790.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存