当前位置:网站首页>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
}
}
}
边栏推荐
- Motivation du Protocole de chiffrement avancé AES
- 地平线2022年4月最新方案介绍
- BBR 遭遇 CUBIC
- Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
- Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
- 海思调用接口之Makefile配置
- golang中new与make的区别
- Splunk audit 的设定
- Numerical solution of partial differential equations with MATLAB
- Win11如何开启目视控制?Win11开启目视控制的方法
猜你喜欢
![[npuctf2020]ezlogin XPath injection](/img/6e/dac4dfa0970829775084bada740542.png)
[npuctf2020]ezlogin XPath injection

Chow-Liu Tree

Lambda expression: an article takes you through

Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs

AES高級加密協議的動機闡述

抖音实战~点赞数量弹框

Motivation du Protocole de chiffrement avancé AES

损失函数~

Successfully changed Splunk default URL root path

Introduction to the latest plan of horizon in April 2022
随机推荐
Win11系统explorer频繁卡死无响应的三种解决方法
Lc173. Binary search tree iterator
Go multithreaded data search
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
PotPlayer设置最小化的快捷键
情感对话识别与生成简述
Jerry's fast touch does not respond [chapter]
Use of recyclerview with viewbinding
Sword finger offer II 099 Sum of minimum paths - double hundred code
pytorch训练CPU占用持续增长(bug)
AES高级加密协议的动机阐述
Motivation du Protocole de chiffrement avancé AES
The motivation of AES Advanced Encryption Protocol
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
最小生成树 Minimum Spanning Tree
Generics and reflection, this is enough
Potplayer set minimized shortcut keys
Looking at Ctrip's toughness and vision from the Q1 financial report in 2022
容器化技术在嵌入式领域的应用
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06