AD/DA
介绍
硬件电路模型
硬件电路
运算放大器
运放电路
DA原理
原理图
AD原理
AD/DA性能指标
XPT2046
XPT2046时序
原理图
AD模数转换可调电阻光敏温度电阻
XPT2046.c
#include <REGX52.H>
sbit XPT2046_CS=P3^5;
sbit XPT2046_DCLK=P3^6;
sbit XPT2046_DIN=P3^4;
sbit XPT2046_DOUT=P3^7;
unsigned int XPT2046_ReadAD(unsigned char Command)
{
unsigned int ADVAlue=0;
unsigned char i;
XPT2046_CS=0;
XPT2046_DCLK=0;
for(i=0;i<8;i++)
{
XPT2046_DIN=Command&(0x80>>i);
XPT2046_DCLK=1;
XPT2046_DCLK=0;
}
for(i=0;i<16;i++)
{
XPT2046_DCLK=1;
XPT2046_DCLK=0;
if(XPT2046_DOUT){ADVAlue|=(0x8000>>i);}
}
XPT2046_CS=1;
if(Command&0x08)
{
return ADVAlue>>8;
}
else
{
return ADVAlue>>4;
}
}
XPT2046.h
#ifndef __XPT2046_H__
#define __XPT2046_H__
#define XPT2046_XP_8 0x9C//0x8C
#define XPT2046_YP_8 0xDC
#define XPT2046_AUX_8 0xEC
#define XPT2046_VBAT_8 0xAC
#define XPT2046_XP_12 0x94//0x84
#define XPT2046_YP_12 0xD4
#define XPT2046_AUX_12 0xE4
#define XPT2046_VBAT_12 0xA4
unsigned int XPT2046_ReadAD(unsigned char Command);
#endif
main.c
#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "XPT2046.h"
unsigned int ADValue;
void main()
{
LCD_Init();
LCD_ShowString(1,1,"ADJ NTC RG");
while(1)
{
ADValue=XPT2046_ReadAD(XPT2046_XP_8);
LCD_ShowNum(2,1,ADValue,3);
ADValue=XPT2046_ReadAD(XPT2046_YP_8);
LCD_ShowNum(2,5,ADValue,3);
ADValue=XPT2046_ReadAD(XPT2046_VBAT_8);
LCD_ShowNum(2,9,ADValue,3);
Delay(10);
}
}
运行效果
DA数模转换呼吸灯
main.c
#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "Nixie.h"
#include "Timer0.h"
sbit Motor=P2^1;
unsigned char Counter,Compare;
unsigned char i;
void main()
{
Timer0_Init();
while(1)
{
for(i=0;i<100;i++)
{
Compare=i;
Delay(10);
}
for(i=100;i>0;i--)
{
Compare=i;
Delay(10);
}
}
}
void Timer0_Routine() interrupt 1
{
TL0 = 0x9C; //设置定时初始值
TH0 = 0xFF; //设置定时初始值
Counter++;
Counter%=100;
if(Counter<Compare)
{
Motor=1;
}
else
{
Motor=0;
}
}
标签:20,XPT2046,unsigned,ReadAD,ADDA,ADValue,include,define
From: https://www.cnblogs.com/mzx233/p/17867418.html