2.21ADC
/*
Chuong trinh doc lien tuc gia tri dien the tai kenh 1 cua ADC va hien thi len man hinh
*/
#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <dos.h>
#include <PCIXP.h>
#define pi 3.14143
void main()
{
int add=Get_Addr("PCI_ADC");
int ADC_H, ADC_L,value,voltage;
printf("
\t\tChuong trinh demo ADC, su dung kenh CH1
.");
while(!kbhit())
{
outportb(add,0x01); // Chon kenh CH1
outportb(add+1,0x00); // Select software trigger method
outportb(add+1,0x10); // Set TRI bit
outportb(add+1,0x00); // Clear TRI to start conversion
Sleep(20); // wait for >= 50us to finish conversion
ADC_L = inportb(add); // Byte thap
ADC_H = inportb(add+1); // Byte cao
value = (ADC_L&0xff) | (ADC_H<<8);
value = value&0xfff;
voltage = (value * 20)/4095 - 10;
printf("\rGia tri dien ap doc duoc la: %5d Vol", voltage);
//Sleep(100);
}
}
Bạn đang đọc truyện trên: Truyen247.Pro