PIC12F683微控制器實(shí)驗(yàn)板
連接UTX和SW1引腳GP0(引腳7)和GP1端口分別。
PC端:
連接RX(2),TX(3)和GND(5)針板相應(yīng)的PC機(jī)的RS232端口引腳。此外,在PC上定義以下設(shè)置一個新的連接的超級終端窗口。
BPS = 9600,數(shù)據(jù)位= 8;校驗(yàn)=無,停止位= 1; =硬件流量控制
軟件
/*
PIC12F683 Experiment Board
Experimen No. 3 : Read analog voltage from AN0 and diplay
on Hyperterminal window on PC using Software UART.
Date: 06/25/2010
*/
char Message1[] = Digital Value= ;
unsigned int adc_value, backup=0 ;
char *temp = 0000, error;
int i;
void main() {
CMCON0 = 7;
TRISIO = 11; // GPIO 0, 1, 3 Inputs; Rest are O/Ps
ANSEL = 0;
GPIO = 0;
// Define GPIO.3 as UART Rx, and 5 as Tx
error = Soft_UART_Init(GPIO,3, 5, 9600, 0 );
Delay_ms(100);
do {
adc_value = ADC_Read(0);
if(adc_value != backup) {
if (adc_value/1000)
temp[0] = adc_value/1000 + 48;
else
temp[0] = '0';
temp[1] = (adc_value/100)%10 + 48;
temp[2] = (adc_value/10)%10 + 48;
temp[3] = adc_value%10 + 48;
for (i=0; i= 13; i++) {
Soft_UART_Write(Message1[i]);
Delay_ms(50);
}
for (i=0; i= 3; i++) {
Soft_UART_Write(temp[i]);
Delay_ms(50);
}
Soft_UART_Write(10); // Line Feed
Soft_UART_Write(13); // Carriage Return
backup = adc_value;
}
delay_ms(100);
} while(1);
}
輸出
相應(yīng)的模擬輸入數(shù)字號碼將顯示在超級終端窗口。您可以改變電位器和數(shù)字同等數(shù)量也將發(fā)生變化。請記住,ADC是10位,讓您在屏幕上看到的數(shù)量將會從0000到1023。
評論