当前位置:网站首页>The use of 8255 interface chip and ADC0809
The use of 8255 interface chip and ADC0809
2022-07-02 23:13:00 【The universe is hidden in the book】
The experiment purpose : utilize 8255 Interface chip and ADC0809 Realize the reading of analog voltage
Experimental circuit :
Detailed code :
#include<reg51.h>
#include<absacc.h>
#define PA_ADDR XBYTE[0x300] //PA mouth , Segment code port
#define PB_ADDR XBYTE[0x301] //PB mouth , Bit scanning port
#define PC_ADDR XBYTE[0x302] //PC mouth ,AD Conversion data port
#define CMD_ADDR XBYTE[0x303] //8255 Command port
sbit start= P1^0; //ADC0809 Start signal
sbit adda= P1^1; // Channel selection
sbit addb= P1^2;
sbit addc= P1^3;
sbit eoc= P1^4; // Conversion end signal
sbit baoj=P3^1;//waring light
sbit buzz=P3^2;//warning voice
sbit xuanzhe=P1^6;// Press the key to select the channel
unsigned char flag=0; //50ms To the flag
unsigned char code SEG[10]={
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d, 0x07,0x7f,
0x6f};
unsigned char code SEG1[10]={
0xbf,0x86,0xdb,0xcf, 0xe6,0xed,0xfd, 0x87,0xff,
0xef};
unsigned char dispbuf[3]={
1,1,0}; // Display 100 bits of buffer
void Timer0_Init()
{
TMOD=0x01; // Timer 0 The way 1
TH0=(65536-5000)/256; // timing 5ms
TL0=(65536-5000)%256;
ET0=1; // Open the interrupt
EA=1;
TR0=1; // Turn on the timer 0
}
void Timer0_ISR() interrupt 1 using 0
{
static unsigned char i=0,k=0;
TH0=(65536-5000)/256; // Reset the initial value
TL0=(65536-5000)%256;
k++;
if(k==10)
{
k=0;
flag=1; //50ms Arrival rule flag Set up 1
}
PB_ADDR=0xff; // Turn off all nixie tubes
if(i!=2) PA_ADDR= SEG[dispbuf[i]] ; // Sending segment code
else PA_ADDR= SEG1[dispbuf[i]] ; // The highest digit shows the decimal point
PB_ADDR=~(0x01<<i); // Send scanning code
i++;
if(i==3)i=0;
// }
}
void display(unsigned int m)
{
dispbuf[2]= m/100 ; // Get a hundred
dispbuf[1]= m/10%10 ; // Get ten
dispbuf[0]= m%10 ; // Get bits
}
void delay()
{
unsigned char i;
for(i=0;i<120;i++); // Time delay 1ms
}
/*AD transformation , It is read according to the sequence diagram , AD0809 The drive design of */
unsigned char ad_converse() //AD Conversion function
{
unsigned char temp;
if(xuanzhe==1)
{
addc=0;addb=1; adda=1;} // Select the channel 6
else
{
addc=1 ; addb=0 ; adda=1;}// Select the channel 5
start= 1 ;
delay();
start= 0 ; //start The falling edge of the signal latches the channel , start-up AD
if(!eoc) ; // wait for eoc Lower
if(eoc) ; // wait for eoc When it gets higher, the conversion ends
temp=PC_ADDR; // from PC Read the conversion result to temp
return temp; // return AD Conversion result
}
void main()
{
unsigned int xianzhi_1;
unsigned char adresult;
unsigned int voltage;
CMD_ADDR=0x89 ; //8255 initialization , The way 0,A Mouth and B output ,C I want to input
Timer0_Init();
buzz=0;
xianzhi_1=250;
while(1)
{
if(flag==1) // Determine whether 50ms It's time to
{
flag=0;
adresult=ad_converse(); // Start once AD transformation , The results are stored in adresult
voltage=PC_ADDR*500.00/256; // Digital quantity is converted into voltage value
if(voltage>xianzhi_1)// range of waring is yourself setting,this is 2.50V
{
baoj=~baoj;
buzz=1;}
else
{
baoj=0;
buzz=0;
}
disp ay(voltage); // Display the voltage value
}
}
}
边栏推荐
- 程序员版本的八荣八耻~
- Lambda expression: an article takes you through
- 用matlab调用vs2015来编译vs工程
- Detailed explanation and application of merging and sorting
- Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
- Application of containerization technology in embedded field
- SQL advanced syntax
- Lambda表达式:一篇文章带你通透
- 严守工期,确保质量,这家AI数据标注公司做到了!
- 2016. 增量元素之间的最大差值
猜你喜欢

Chow-Liu Tree

实现BottomNavigationView和Navigation联动

Use of recyclerview with viewbinding

Prometheus deployment
![[redis notes] compressed list (ziplist)](/img/83/ff38fabb1baebc5fa4d3d72da315dc.png)
[redis notes] compressed list (ziplist)

The motivation of AES Advanced Encryption Protocol

Pandora IOT development board learning (HAL Library) - Experiment 4 serial port communication experiment (learning notes)

Odoo13 build a hospital HRP environment (detailed steps)

Go language sqlx library operation SQLite3 database addition, deletion, modification and query

损失函数~
随机推荐
The difference between new and make in golang
Stop slave is stuck -- the event of the transaction is not copied completely
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
Introduction to the latest plan of horizon in April 2022
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
地平线2022年4月最新方案介绍
Mask R-CNN
密码技术---分组密码的模式
Tiktok actual combat ~ number of likes pop-up box
Minimum spanning tree
Quantitative analysis of PSNR, SSIM and RMSE
Learning records of data analysis (II) -- simple use of response surface method and design expert
Lc173. Binary search tree iterator
20220524_数据库过程_语句留档
Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP
Pytorch training CPU usage continues to grow (Bug)
2016. maximum difference between incremental elements
容器化技术在嵌入式领域的应用
提交代码流程
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]