当前位置:网站首页>Single chip microcomputer: d/a output
Single chip microcomputer: d/a output
2022-06-13 03:53:00 【DC-STDIO】
List of articles
Preface
Today, I would like to introduce the basic concepts of single chip microcomputer ,D/A Output
D/A Output
D/A Is and A/D Just in the opposite direction , One 8 Bit D/A, from 0~255, On behalf of 0~2.55 V Words , Then we use MCU to send the third byte 100,D/A The pin will output a 1 V The voltage of , send out 200 Just output one 2 V The voltage of , It's simple , We use a simple program to realize , And through 、 Press the button to increase or decrease the output amplitude value , Increase or decrease each time 0.1 V. If you have a multimeter , You can test it directly on the board AOUT Output voltage at point , Watch it change . because PCF8591 Of DA The maximum output bias error is 50 mv( Provided by the data book ), Therefore, the error between the voltage value measured by the multimeter and the theoretical value should be within 50 mV within .
#include <reg52.h>
unsigned char T0RH = 0; //T0 High byte of overloaded value
unsigned char T0RL = 0; //T0 The low byte of the overloaded value
void ConfigTimer0(unsigned int ms);
extern void KeyScan();
extern void KeyDriver();
extern void I2CStart();
extern void I2CStop();
extern bit I2CWrite(unsigned char dat);
void main(){
EA = 1; // General interruption
ConfigTimer0(1); // To configure T0 timing 1ms
while (1){
KeyDriver(); // Call the key driver
}
}
/* Set up DAC Output value ,val- The set value */
void SetDACOut(unsigned char val){
I2CStart();
if (!I2CWrite(0x48<<1)){
// Addressing PCF8591, If not answered , Stop the operation and return to
I2CStop();
return;
}
I2CWrite(0x40); // Write control byte
I2CWrite(val); // write in DA value
I2CStop();
}
/* Key action function , Perform the corresponding operation according to the key code ,keycode- Key code */
void KeyAction(unsigned char keycode){
static unsigned char volt = 0; // Output voltage value , Implies a decimal decimal place
if (keycode == 0x26){
// Up key , increase 0.1V Voltage value
if (volt < 25){
volt++;
SetDACOut(volt*255/25); // Convert to AD Output value
}
}else if (keycode == 0x28){
// Down key , Reduce 0.1V Voltage value
if (volt > 0){
volt--;
SetDACOut(volt*255/25); // Convert to AD Output value
}
}
}
/* Configure and start T0,ms-T0 Timing time */
void ConfigTimer0(unsigned int ms){
unsigned long tmp; // Temporary variable
tmp = 11059200 / 12; // The timer counts the frequency
tmp = (tmp * ms) / 1000; // Calculate the required count
tmp = 65536 - tmp; // Calculate timer overload value
tmp = tmp + 28; // Compensate for the error caused by interrupt response delay
T0RH = (unsigned char)(tmp>>8); // The timer overload value is split into high and low bytes
T0RL = (unsigned char)tmp;
TMOD &= 0xF0; // Zero clearing T0 Control bit of
TMOD |= 0x01; // To configure T0 For mode 1
TH0 = T0RH; // load T0 Overload value
TL0 = T0RL;
ET0 = 1; // Can make T0 interrupt
TR0 = 1; // start-up T0
}
/* T0 Interrupt service function , Perform key scan */
void InterruptTimer0() interrupt 1{
TH0 = T0RH; // Reload overloaded values
TL0 = T0RL;
KeyScan(); // Key scan
}
边栏推荐
- 大五人格学习记录
- What to bring to 2022
- Precautions for stream flow
- 单片机:EEPROM介绍与操作
- Jumpserver installation
- [multithreading] what is multithreading in the end -- the elementary level of multithreading (review for self use)
- Lambda end operation collect
- On the value of line height
- 2022 spring semester summary
- 四旋翼飞行器避障系统基础
猜你喜欢

LVS four layer load balancing cluster (6) LVS working mode

USB-IF BC1.2充电协议解读

【测试开发】软件测试基础篇

Interpretation of mobile phone private charging protocol
![[web] cookies and sessions](/img/00/b10a9f4ae918afe5d032a9af20a49c.png)
[web] cookies and sessions

UDP connection map collection

GoFrame第四天

Synching build your own synchronization cloud

leetcode. 1 --- sum of two numbers

【测试开发】自动化测试selenium篇(一)
随机推荐
2022 spring semester summary
2022春学期总结
Lambda termination operation find and match anymatch
任总与系统工程领域科学家、专家会谈纪要
Big Five personality learning records
Multi thread implementation of selling tickets and producers and consumers
How can a sweeping robot avoid obstacles without "mental retardation"? Analysis of five mainstream obstacle avoidance techniques
Lambda终结操作collect
MCU: NEC protocol infrared remote controller
大疆无人机飞控系统的原理、组成及各传感器的作用
[test development] automated test selenium (II) -- common APIs for webdriver
[Yugong series] June 2022 Net architecture class 080 master cluster and database switching of distributed middleware schedulemaster
GoFrame第四天
单片机:A/D(模数转换)的主要指标
Tencent cloud instant messaging IM
解答私信@田田WX //2022-6-12 C语言 51单片机LED模拟交通灯
Lambda end operation reduce merge
EGO Planner代码解析----CMakeLists.txt和package.xml
[note]vs2015 compilation of masm32 using MASM32 Library
[test development] advanced part - Classification of various test technologies