汇编代码:
程序代码
LED_0 EQU 30H
LED_1 EQU 31H
LED_2 EQU 32H
ADC EQU 35H
CLOCK BIT P24
ST BIT P25
EOC BIT P26
OE BIT P27
ORG 00H
SJMP START
ORG 0BH
LJMP INT_T0
START: MOV LED_0, #00H
MOV P2, #0FFH
MOV LED_1, #00H
MOV LED_2, #00H
MOV DPTR, #TABLE
MOV TMOD, #02H
MOV TH0, #245H
MOV TL0, #00H
MOV IE, #82H
SETB TR0
WAIT: CLR ST
SETB STH
CLR ST
JNB EOC, $
SETB OE
MOV ADC, P1
CLR OE
MOV A, ADC
MOV B, #51
DIV AB
MOV LED_2, A
MOV A, B
MOV B, #5
DIV AB
MOV LED_1, A
MOV LED_0, B
LCALL DISP
SJMP WAIT
INT_T0: CPL, CLOCK
RETI
DISP: MOV A, LED_0
MOVC A, @A+DPTR
CLR P23
MOV P0, A
LCALL DELAY
SETB P23
MOV A, LED_1
MOVC A,@A+DPTR
CLR P22
MOV P0, A
LCALL DELAY
SETB P22
MOV A, LED_2
MOVC A, @A+DPTRL
CLR P21
ORL A, #80H
MOV P0, A
LCALL DELAY
SETB P21
RET
DELAY: MOV R6, #10
D1: MOV R7, #250
DJNZ R7, $
DJNZ R6, D1
RET
TABLE: DB 3FH, 06H, 5BH, 4FH, 66H
DB 6DH, 7DH, 07H, 7FH, 6FH
END
这是吴鉴鹰单片机开发板配套的例程。
/-----------------------------------------------
名称:IIC协议 PCF8591 AD/DA转换
内容:使用4路AD中的4路检测外部模拟量输入 使用液晶显示
------------------------------------------------/
#include <reg52h>
#include "i2ch"
#include "delayh"
#include "1602h"
#include <stdioh>
#define AddWr 0x90 //写数据地址
#define AddRd 0x91 //读数据地址
extern bit ack;
unsigned char ReadADC(unsigned char Chl);
bit WriteDAC(unsigned char dat);
/------------------------------------------------
主程序
------------------------------------------------/
main()
{
unsigned char num=0,i;
unsigned char temp[7];//定义显示区域临时存储数组
float Voltage; //定义浮点变量
LCD_Init(); //初始化液晶
DelayMs(20); //延时有助于稳定
LCD_Clear(); //清屏
while (1) //主循环
{
for(i=0;i<5;i++) //连续读5次,取最后一次,以便读取稳定值
num=ReadADC(0); //读取第1路电压值,范围是0-255
Voltage=(float)num5/256; //根据参考电源VREF算出时间电压,float是强制转换符号,用于将结果转换成浮点型
sprintf(temp,"V0 %32f ",Voltage);//格式输出电压值,%32f 表示浮点输出,共3位数,小数点后2位
LCD_Write_String(0,0,temp);
for(i=0;i<5;i++)
num=ReadADC(1);
Voltage=(float)num5/256;
sprintf(temp,"V1 %32f ",Voltage);
LCD_Write_String(8,0,temp);
for(i=0;i<5;i++)
num=ReadADC(2);
Voltage=(float)num5/256;
sprintf(temp,"V2 %32f ",Voltage);
LCD_Write_String(0,1,temp);
for(i=0;i<5;i++)
num=ReadADC(3);
Voltage=(float)num5/256;
sprintf(temp,"V3 %32f ",Voltage);
LCD_Write_String(8,1,temp);
//主循环中添加其他需要一直工作的程序
DelayMs(200);
}
}
/------------------------------------------------
读AD转值程序
输入参数 Chl 表示需要转换的通道,范围从0-3
返回值范围0-255
*** 作分四步:
(1)、发送地址字节,选择该器件。
(2)、发送控制字节,选择相应通道。
(3)、重新发送地址字节,选择该器件的读写。
(4)、接收目标通道的数据。
------------------------------------------------/
unsigned char ReadADC(unsigned char Chl)
{
unsigned char Val;
Start_I2c(); //启动总线
SendByte(AddWr); //发送器件地址
if(ack==0)return(0);
SendByte(0x40|Chl); //发送器件子地址
if(ack==0)return(0);
Start_I2c();
SendByte(AddWr+1); //1001 0001 是读命令
if(ack==0)return(0);
Val=RcvByte();
NoAck_I2c(); //发送非应位
Stop_I2c(); //结束总线
return(Val);
}
我这里有protues+代码:(内容是串口通信,A机测量,B机数码管显示)
代码给你吧,protues 需要再说
#include <reg51h>
#define uint unsigned int
#define uchar unsigned char
#define PinData P0
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit PinSTART = P1^5;
sbit PinOE = P1^6;
sbit PinEOC = P1^7;
sbit CLK = P3^4;
//短延时函数:ShortDelay()
void nNop(uchar i)
{
for(;i>0;i--) ;
}
//长延时函数:LongDelay()
void LongDelay(uint i)
{
uint j;
for(;i>0;i--)
{ for(j=1000;j>0;j--);}
}
//引脚初始化
void InitIO()
{
PinData = 0xff;
PinSTART = 1;
PinEOC = 1;
PinOE = 1;
CLK = 1;
}
//UART的初始化:模式1,8位,9600Bds
void InitSerial()
{
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11059MHz
TL1 = 0xF4; // 9600 Bds at 11059MHz
TR1 = 1; // Timer 1 run
PCON = 0x00; // Timer 1 run
SCON = 0x50; // uart in mode 1 (8 bit), REN=1
}
//T0定时脉冲中断初始化
void init_uart()
{
TMOD=0x01;
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
TR0=1;
// ET0=1;
EA=1;
}
//等待A/D转换结束函数:WaitADCEnd()
void WaitADCEnd(void)
{
while(!PinEOC) ;
}
//读取A/D转换后的数据函数:ReadData()
uchar ReadData()
{
uchar tempt;
ET0=1;
PinSTART = 0;
//nNop(1);
PinSTART = 1;
PinSTART = 0;
WaitADCEnd();
PinOE =1;
nNop(2);
tempt = PinData & 0xff;
ET0=0;
return(tempt);
//PinOE =0;
}
//子机送数据给主机
void sendtomain(uchar temp)
{
SBUF = temp;
while(!TI);
TI=0;
}
void main()
{
uchar temp, tab;
InitIO();
init_uart();
InitSerial();
while(1)
{
temp = ReadData();
sendtomain(temp);
while(!RI);
tab = SBUF;
RI = 0;
if(tab == 0)
{
LED0 = 1;
LED1 = 0;
}
else if(tab == 1)
{
LED0 = 1;
LED1 = 1;
}
else
{
LED0 = 0;
LED1 = 1;
}
}
}
void clk(void) interrupt 1 using 0
{
TH0= (65536-4000)/256;
TL0= (65536-4000)%256;
CLK= ~CLK;
}
#include<reg51h>
#define PDATA P2
#define aver 2
#define uint unsigned int
#define uchar unsigned char
sbit Ledlow = P1^3;
sbit Ledhig = P1^4;
uchar table2 []={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar table1 []={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
//短延时函数:ShortDelay()
void nNop(uchar temp)
{
uint i;
for(i=0 ;i<temp; i++) ;
}
//UART初始化:模式1,8位,9600Bds at 11059MHz
void InitSerial()
{ // uart in mode 1 (8 bit), REN=1
TMOD = 0x20 ; // Timer 1 in mode 2
TH1 = 0xF4; // 9600 Bds at 11059MHz
TL1 = 0xF4; // 9600 Bds at 11059MHz
TR1 = 1;
PCON = 0x00; // Timer 1 run
SCON = 0x50;
}
//主机接受信息给从机
uchar recivefromslave()
{
uchar temp;
while(!RI);
temp=SBUF;
RI=0;
return(temp);
}
// 显示
void leddisp(uint temp )
{
uint i;
uint getdata1 = 0;
uint getdata2 = 0;
temp=tempaver;
getdata1=temp/100;
getdata2=temp/10;
getdata2=getdata2%10;
for(i=0;i<30;i++)
{
PDATA=table1[getdata1];
Ledlow =0;
Ledhig = 1;
nNop(1000);
Ledlow =0;
Ledhig = 0;
PDATA=table2[getdata2];
Ledlow =1;
Ledhig = 0;
nNop(1000);
Ledlow =0;
Ledhig = 0;
}
}
void main()
{
uint tab;
uint tempt;
Ledlow = 0;
Ledhig = 0;
PDATA = 0x00;
InitSerial();
while(1)
{
tempt = (uint) recivefromslave(); //接收从机采集的信息
leddisp(tempt); //显示信息
if(tempt<0x60) //判断信息
{
tab = 0;
}
else if(tempt>0xc0)
{
tab = 2;
}
else
{
tab = 1;
}
SBUF = (uchar)tab; //对采集信息进行控制
while(!TI);
TI = 0;
}
}
行注释用 //
段注释用 /内容/
回答不对?
你看看adc0808,0809的使用笔记手册之类的吧,相对来说这个很简单的,就是时序 *** 作,给一个时钟给adc,选择通道,等待转换完成,读取数据,转换数据
//实验用程序 测试通过 STC15F2K60S2 @110592MHZ
#include "reg51h"
#include "intrinsh"
typedef unsigned char BYTE;
typedef unsigned int WORD;
sfr ADC_CONTR = 0xBC;
sfr ADC_RES = 0xBD;
sfr ADC_LOW2 = 0xBE;
sfr P1ASF = 0x9D;
BYTE ch = 0; //ADC回路数
/----------------------------
延时
----------------------------/
void Delay(WORD n){
WORD x;
while (n--){
x = 5000;
while (x--);
}
}
/----------------------------
ADC中断
----------------------------/
void adc_isr() interrupt 5 using 1{
ADC_CONTR &= !0x10;
P2=ADC_RES;
ADC_CONTR = 0x80 | 0x00 | 0x08 | ch;
}
/----------------------------
初始化ADC
----------------------------/
void InitADC(){
P1ASF = 0xff;
ADC_RES = 0;
ADC_CONTR = 0x80 | 0x00 | 0x08 | ch;;
Delay(2);
}
void main(){
InitADC(); //初始化ADC
IE = 0xa0;
while (1);
}
以上就是关于adc0809数字电压表,用汇编语言,求代码全部的内容,包括:adc0809数字电压表,用汇编语言,求代码、利用STC89C52单片机以及PCF8591的AD转换设计一个数字电压表,求大神给个程序例子,在线等!!!急!!!、能帮帮编写个单片机数字电压表仿真设计的程序代码吗用C语言。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)