C.1.6 Final Result
The PICSimLab board created for this tutorial are shown in the figure below.
The sample program below can be used to test new board, this code is write for XC8 compiler:
1#include <xc.h>; 2 3#include "config_4550.h" 4#include "adc.h" 5#include "serial.h" 6#include "itoa.h" 7 8void main() 9{ 10 unsigned int val; 11 char buffer[10]; 12 13 ADCON1=0x02; 14 TRISA=0xFF; 15 TRISB=0xFC; 16 TRISC=0xBF; 17 TRISD=0xFF; 18 TRISE=0x0F; 19 20 adc_init(); 21 serial_init(); 22 23 24 while(1) 25 { 26 val=adc_amostra(0); 27 28 if(PORTDbits.RD1) 29 { 30 if(val > 340) 31 PORTBbits.RB0=1; 32 else 33 PORTBbits.RB0=0; 34 35 if(val > 680) 36 PORTBbits.RB1=1; 37 else 38 PORTBbits.RB1=0; 39 } 40 else 41 { 42 if(PORTDbits.RD0) 43 { 44 PORTBbits.RB0=1; 45 PORTBbits.RB1=0; 46 } 47 else 48 { 49 PORTBbits.RB0=0; 50 PORTBbits.RB1=1; 51 } 52 53 } 54 55 serial_tx_str(itoa(val,buffer)); 56 serial_tx_str("' r' n"); 57 } 58 59}