当前位置:网站首页>Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
2022-06-30 03:15:00 【LH_ SMD】
1. Hardware
STC89C52/90C516RD/89C516RD etc.
Crystal oscillator :11.0592M
Memory configuration :
Memory Model by small, Selecting other may not work properly .
2. Code
adc0832.h
#ifndef __ADC0832_H__
#define __ADC0832_H__
#include <reg52.h>
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
sbit CS = P1^0;
sbit Clk = P1^1;
sbit DATI = P1^2;
sbit DATO = P1^2;
uchar get_adc0832_data(uchar CH);
#endif
adc0832.c
#include "adc0832.h"
#include <stdlib.h>
#include <intrins.h>
uint dat = 0x00; //AD value
uchar CH; // Channel variables
uchar data dis[] = {
0x00, 0x00,0x00,0x00}; // Display value
/* Function description : obtain ADC0832 data Parameters :CH 0 perhaps 1 Represents its two different channels Return value : Measured ADC value */
uchar get_adc0832_data(uchar CH)
{
uchar i,test,adval;
adval = 0x00;
test = 0x00;
Clk = 0; // initialization
DATI = 1;
_nop_();
CS = 0;
_nop_();
Clk = 1;
_nop_();
if ( CH == 0x00 ) // Channel selection
{
Clk = 0;
DATI = 1; // passageway 0 First of all
_nop_();
Clk = 1;
_nop_();
Clk = 0;
DATI = 0; // passageway 0 The second of
_nop_();
Clk = 1;
_nop_();
}
else
{
Clk = 0;
DATI = 1; // passageway 1 First of all
_nop_();
Clk = 1;
_nop_();
Clk = 0;
DATI = 1; // passageway 1 The second of
_nop_();
Clk = 1;
_nop_();
}
Clk = 0;
DATI = 1;
for( i = 0;i < 8;i++ ) // Before reading 8 The value of a
{
_nop_();
adval <<= 1;
Clk = 1;
_nop_();
Clk = 0;
if (DATO)
adval |= 0x01;
else
adval |= 0x00;
}
for (i = 0; i < 8; i++) // After reading 8 The value of a
{
test >>= 1;
if (DATO)
test |= 0x80;
else
test |= 0x00;
_nop_();
Clk = 1;
_nop_();
Clk = 0;
}
if (adval == test) // Compare the former 8 Bit and back 8 The value of a , If not, leave it . If it keeps appearing, it will be displayed as zero , Please remove this line
dat = test;
nop_();
CS = 1; // Release ADC0832
DATO = 1;
Clk = 1;
return dat;
}
边栏推荐
- Neo4j---性能优化
- Dripping backward (II)
- *Write a program to initialize a string object with a vector < char> container*/
- [live broadcast notes 0629] Concurrent Programming II: lock
- Neo4j--- performance optimization
- Global and Chinese market of centrifugal pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- Prompt learning a blood case caused by a space
- Federal learning: dividing non IID samples by Dirichlet distribution
- Shell counts all strings before the last occurrence of a string
- 【实战技能】如何撰写敏捷开发文档
猜你喜欢

Auto. JS learning notes 16: save to the mobile phone by project, instead of saving a single JS file every time, which is convenient for debugging and packaging

F1C100S自制开发板调试过程

X书6.97版本shield-unidbg调用方式

发现mariadb数据库时间晚了12个小时

Summary of PHP test sites encountered in CTF questions (I)

【十分钟】manim安装 2022

Simple custom MVC optimization

HOOK Native API

2. successfully solved bug:exception when publishing [Failed to connect and initialize SSH connection...

Linked list: insert a node in the head
随机推荐
Global and Chinese market for sensor screwdrivers 2022-2028: Research Report on technology, participants, trends, market size and share
HOOK Native API
Hands on in-depth learning notes (XV) 4.1 Multilayer perceptron
2. successfully solved bug:exception when publishing [Failed to connect and initialize SSH connection...
OP diode limit swing
个人PC安装软件
Use of custom MVC
正则全匹配:密码由8位以上数字,大小写字母,特殊字符组成
What are outer chain and inner chain?
Dripping backward (II)
How to set password complexity and timeout exit function in Oracle
行政路线编码 字母+数字的排序方式
HOOK Native API
GTK interface programming (II): key components
How does the trading platform for speculation in spot gold ensure capital security?
X书6.89版本shield-unidbg调用方式
【微信小程序】条件渲染 列表渲染 原来这样用?
WPF Initialized事件在.cs中绑定不被触发的原因
mysql 主从数据库同步失败的原因
QT中foreach的使用