matildaa
Newbie level 1
hi!i just learm about programming and microc.so here is my mini project need to be done.i want the led to turn on when temperature drop below 38 degrees and turn off when rise above 38 degrees but it doesnt work that way.im using LM35 temperature sensor and make it as high priority interrupt.and timer as low priority interrupt.is my connection wrong or my coding wrong?help me thank you in advancee
coding
circuit
coding
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 #include<p18F458.inc> ;assembler directive lp_cnt1 set 0x31 lp_cnt2 set 0x32 TEMP_L set 0x33 TEMP_H set 0x34 BIN_TEMP set 0x35 max set 0x26 ;macro directive dup_nop macro kk variable i i=0 while i<kk nop i+=1 endw endm ;program start template org 0x00 goto start org 0x08 goto temperature retfie org 0x18 goto alarm retfie ;main program start setf TRISA,A;configure port A as input because of the temperature sensor is input clrf TRISC,A ;configure portC as the output for buzzer/speaker clrf TRISD,A;configure portD as output for LED movlw D'78' movff WREG,max movlw 0x81 movwf ADCON0,A movlw 0xCE movwf ADCON1,A ;************************************************************** ;configure the analog digital for the conversion of temperature ;************************************************************** bcf RCON,IPEN,A bsf INTCON,TMR0IE,A bcf INTCON,TMR0IF,A bcf INTCON2,TMR0IP,A ;*************************************************************** ;configure the timer0 as interrupt low priority ;for turning alarm system ;*************************************************************** bsf IPR1,ADIP,A bsf PIE1,ADIE,A bcf PIR1,ADIF,A bsf INTCON,GIEL,A bsf INTCON,GIEH,A ;*************************************************************** ;configure analog digital interrup and set to high priority ;*************************************************************** movlw 0x87 movwf T0CON,A movlw 0xFD movwf TMR0H,A movlw 0x5C movwf TMR0L,A ;**************************************************************** ;initialize the timer0 for 6 hours ;we assume the frequency to be 32Hz and selected presacaler 256 ;**************************************************************** again nop bra again ;wait the interrupt to happen alarm bcf INTCON,TMR0IF,A movlw 0xFD movwf TMR0H,A movlw 0x5C movwf TMR0L,A setf PORTC,A call delay call delay call delay call delay call delay call delay call delay call delay call delay call delay clrf PORTC,A bsf INTCON,GIEL return ;****************************************** ;alarm will sound every 6 hours for 10second ;****************************************** temperature bsf ADCON0,GO check btfsc ADCON0,DONE bra check movff ADRESL,TEMP_L movff ADRESH,TEMP_H call ALGO_10_to_8 ; TO CONVERT 10 BIT TO 8 BIT OUTPUT cpfsgt max,A bra off_led bra on_led on_led setf PORTD,A bsf INTCON,GIEH return off_led clrf PORTD,A bsf INTCON,GIEH return ;************************************************************ ;check if the temperature drop below 35degree,led will on ;if the temperarure rise above 35 degree, led will turn off ;************************************************************ delay movlw D'250'; movwf lp_cnt1,A; loop1 movlw D'200'; movwf lp_cnt2,A; loop2 dup_nop D'197'; decfsz lp_cnt2,F,A; bra loop2; decfsz lp_cnt1,F,A; bra loop1; nop return ;************************************************************ ;delay 1second basic time block=20us frequency=40MHz ;************************************************************ ALGO_10_to_8 RLNCF TEMP_L,F ; ROTATE ONE TO LEFT, STORE IT IN FILE REGISTER RLNCF TEMP_L,W ; ROTATE ONE TO LEFT, STORE IT IN WREG ANDLW 0X03 ; THE CLEAR THE 6 MOST SIGNIFICANT MOVWF TEMP_L ; MOVE WREG TO TEMP_L RLNCF TEMP_H,F ; ROTATE ONE TO LEFT, STORE IT IN FILE REGISTER RLNCF TEMP_H,W ; ROTATE ONE TO LEFT, STORE IT IN WREG ANDLW 0xFC ; TO CLEAR THE 2 LEAST SIGNIFICANT IORWF TEMP_L,W ; ADD TEMP_L TO WREG MOVWF BIN_TEMP ; MOVE WREG TO BIN_TEMP MOVF BIN_TEMP,W ; MOVE TO WREG FOR COMPARISON RETURN END
circuit