Chapter 2
Chapter 2
Chapter 2
Software Implementation
program LM35 DIM X,y,g1,i AS WORD DIM XTXT,ytxt,g1txt,tt AS STRING[5] dim ttxt as string[3] sub procedure interrupt if pir1.5=1 then pir1.5=0 if usart_data_ready=1 then usart_read_text(tt,"$") if (tt[0]="0") or (tt[1]="0") then pwm1_change_duty(0) end if if (tt[0]="1") or (tt[1]="1") then pwm1_change_duty(120) end if if (tt[0]="2") or (tt[1]="2") then pwm1_change_duty(195)
end if if (tt[0]="3") or (tt[1]="3") then pwm1_change_duty(255) end if end if end if end sub MAIN: USART_INIT(9600) ytxt="" g1txt="" XTXT="" TRISD.0=1 intcon=%11000000 PIE1=%00100000 PIR1=0 option_reg=%00110000 tmr0=0 pwm1_init(1000) pwm2_init(1000) pwm1_start pwm2_start RUN: IF PORTD.0=0 THEN PWM2_CHANGE_DUTY(255)
ELSE PWM2_CHANGE_DUTY(0) END IF option_reg=%00110000 tmr0=0 for i=0 to 10000 next i ADCON1.0=0 ADCON1.1=0 ADCON1.2=0 ADCON1.3=0 ''set RA0-RA5 AN. & RE0-RE2 as AN ''set RA0-RA5 AN. & RE0-RE2 as AN ''set RA0-RA5 AN. & RE0-RE2 as AN ''set RA0-RA5 AN. & RE0-RE2 as AN
byteTOSTR(tmr0,tTXT) X=ADC_READ(0)/2 y=ADC_READ(6)/2 g1=adc_read(1) ''Temp. Sensor ''Temp. Sensor for motor ''Gas Sensor
WORDTOSTR(X,XTXT) WORDTOSTR(y,yTXT) WORDTOSTR(g1,g1TXT) USART_WRITE_TEXT(XTXT) USART_WRITE_TEXT("T") USART_WRITE_TEXT(YTXT) USART_WRITE_TEXT("U") USART_WRITE_TEXT(G1TXT) USART_WRITE_TEXT("G") USART_WRITE_TEXT(tTXT)