Trích:
Nguyên văn bởi maiduy082
em đang làm 1 bài tập là lấy data 16bit từ adc rồi sau đó truyền vào máy tính .
đoạn code em viết thế này
Code:
#include <16F877A.h>
#include <DEFS_16F877A.h>
#FUSES NOWDT, HS, NOPUT,NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#device 16F877*=16 ADC=10
#use delay(clock=12000000)
#use rs232(baud=9600, parity=N, xmit=pin_C6, rcv=pin_C7, bits=9)
void main()
{
Int16 dulieu_adc,tong;
int8 high,low,count,k;
setup_adc(adc_clock_internal);
setup_adc_ports( ALL_ANALOG);
set_adc_channel(0);
tong = 0;
k = 1;
while (1)
{
while( input(pin_B0) == 1 )
{
count = 45;
while (count>0)
{
delay_ms(5);
dulieu_adc=read_adc();
tong = tong + dulieu_adc;
count--;
}
low = tong % 256;
high = tong / 256;
tong = 0;
delay_us(50);
putc(low);
k = k++;
putc(high);
k = k--;
}
}
}
các anh coi giúp em nhé ,em tách data trên thành 2 data 8 bit .ko biết em tách 8 bit thấp ,8 bit cao như vậy có đúng ko .
thanks các huynh nhìu .
|
Bạn có thể dùng hàm make8() có sẵn của CCS C, xem kỹ trong file help, make8(data, offset)