当前位置:网站首页>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
}
}
}
边栏推荐
- Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
- Sword finger offer II 099 Sum of minimum paths - double hundred code
- Chow-Liu Tree
- Go语言sqlx库操作SQLite3数据库增删改查
- Li Kou brush questions (2022-6-28)
- 20220524_ Database process_ Statement retention
- Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
- The difference between new and make in golang
- Jerry's fast touch does not respond [chapter]
- Use the scroll bar of souI when using the real window in souI
猜你喜欢
Temperature measurement and display of 51 single chip microcomputer [simulation]
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
ServletContext learning diary 1
Set right click to select vs code to open the file
Minimum spanning tree
Xshell configuration xforward forwarding Firefox browser
[Solved] Splunk: Cannot get username when all users are selected“
Redis 过期策略+conf 记录
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
随机推荐
Freshman learning sharing
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
Methods to solve the tampering of Chrome browser and edeg browser homepage
Cryptographic technology -- key and ssl/tls
Cryptography -- the mode of block cipher
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错
C#中Linq用法汇集
海思3559万能平台搭建:在截获的YUV图像上旋转操作
Set right click to select vs code to open the file
Odoo13 build a hospital HRP environment (detailed steps)
Splunk audit 的设定
Li Kou brush questions (2022-6-28)
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - packaging based on thinkphp5 - detailed guidance of the author - July 1, 2022 08:43:
P1007 single log bridge
Win11系统explorer频繁卡死无响应的三种解决方法
4 special cases! Schools in area a adopt the re examination score line in area B!
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
剑指 Offer II 099. 最小路径之和-双百代码