Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

temperature control problem using pic18f458

Status
Not open for further replies.

matildaa

Newbie level 1
Joined
Sep 10, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,319
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 :cry: thank you in advancee

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
circuit.png
 

hi,
are you using MPlab?
can u use C ?


Ps: the circuit ... you should put some 470 ohm rezistors in series with each led and with the speaker to (i would put some buffer like stage with one tranzistor there...) , and , you do not need the 555 ic. I suppose you do some time base with that, anyway you do not need it , since you already have a wery acurate time base : the mcu's oscilator. You can do even a calendar with that mcu if you want....
 
Last edited:

Hi,

Thats always the problem when using someone elses code, if it does not work you are stuck.

Perhaps if you post the site where you got the code from we can see what the whole idea is and how it should run.

Its also uses a strange collection of parts, running a 40mhz and using a 555 timer chip ?

The code you have is Pic Assembly not Mikro C which is a very different programming language.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top