当前位置:网站首页>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
}
}
}
边栏推荐
- Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
- [adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
- Cryptography -- the mode of block cipher
- Redis 过期策略+conf 记录
- 20220524_数据库过程_语句留档
- Deep analysis of data storage in memory - C language
- Loss function~
- PMP project integration management
- [chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
- Splunk audit 的设定
猜你喜欢
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
Niuke network: maximum submatrix
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
Li Kou brush questions (2022-6-28)
Looking at Ctrip's toughness and vision from the Q1 financial report in 2022
Redis expiration policy +conf record
[Solved] Splunk: Cannot get username when all users are selected“
阿里云有奖体验:如何使用 PolarDB-X
数据标注典型案例,景联文科技如何助力企业搭建数据方案
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
随机推荐
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
Mask R-CNN
Learning records of data analysis (II) -- simple use of response surface method and design expert
Odoo13 build a hospital HRP environment (detailed steps)
阿里云有奖体验:如何使用 PolarDB-X
Jerry's built-in shutdown current is 1.2ua, and then it can't be turned on by long pressing [chapter]
Data analysis learning records -- complete a simple one-way ANOVA with Excel
Alibaba cloud award winning experience: how to use polardb-x
20220527_数据库过程_语句留档
Chow-Liu Tree
Temperature measurement and display of 51 single chip microcomputer [simulation]
antd组件upload上传xlsx文件,并读取文件内容
Tiktok actual combat ~ number of likes pop-up box
损失函数~
1px pixel compatibility of mobile terminal, 1px border
LeetCode 968. Monitor binary tree
编辑卡顿
情感对话识别与生成简述
SQL advanced syntax
PMP project integration management