adc0804 with p16f627 interface

Status
Not open for further replies.

mvdmescht

Newbie level 2
Joined
Sep 30, 2006
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,383
my project must read adc output and display 0-5V on 7seg,i managed to get 0-3V to display but circuit seems to freezing at 3v.what can this be?
 

mvdmescht said:
my project must read adc output and display 0-5V on 7seg,i managed to get 0-3V to display but circuit seems to freezing at 3v.what can this be?


You must post you code, hardware to correction ?
 

code for adc0804 to p16f627 measuring 5v,must i also post the circiut diagram for this project??

;--------------------------------------------------------------------------------------------
;initialise
;--------------------------------------------------------------------------------------------
intialise: bsf 3,5 ;selects bank1
movlw 0xff ;sets porta as input port
movwf 5 ;saves settings to porta
movlw 0x21 ;sets rb0 and rb5 as inpiuts on portb(0010 0001)
movwf 6 ;saves settings to portb
bcf 3,5 ;selects bank0
movlw d'07' ;moves 111 to working register
movwf 1fh ;disable comparators

#define int 6,0 ;define rb0 as intterrupt pin for adc
#define wr 6,1 ;define rb1 as write pin for adc#
#define rd 6,2 ;define rb2 as read pin for adc
#define sr_clk 6,3 ;define rb3 as clock for shift reg.
#define sr_data 6,4 ;define rb4 as serial data in for shift reg.
#define switch 6,5 ;define rb5 as switch to controll pic
#define led_2V 6,6 ;define rb6 as led for 2 volt
#define led_3V 6,7 ;define rb7 as led for 3 volt

count equ 20h ;digital output destination
file1 equ 21h ;rotate counter number of times
;---------------------------------------------------------------------------------------------
;startup under any conditions
;---------------------------------------------------------------------------------------------

bsf wr ;set wr pin on adc disable
nop ;no opperation
nop ;no opperation
bcf wr ;clear wr pin on adc to enable
nop ;no opperation
nop ;no opperation
bsf wr ;disable write pin on adc
bsf rd ;disable read pin on adc
;---------------------------------------------------------------------------------------------
;main program
;---------------------------------------------------------------------------------------------

main: clrf count ;clears digital output destination file

;call test_s1 ;sub to test if switch is active
call rd_adc ;sub to read data from adc to pic
call table ;sub to convert output
call test1 ;sub to test for 2
call test2 ;sub to test for 3
call shift_data ;sub to shift to disp
call delay ;sub to disp data for 1sec

;----------------------------------------------------------------------------------------------
;test for switch
;----------------------------------------------------------------------------------------------

test_s1: btfss switch ;test switch pin for one
goto test_s1 ;if not keep on testing
nop ;no opperation
nop ;no opperation
nop ;no opperation
btfss switch ;test switch pin for one
goto test_s1 ;if not start test again
return ;return to main program
;-----------------------------------------------------------------------------------------------
;read adc to pic
;-----------------------------------------------------------------------------------------------

rd_adc: call delay
call delay
call delay
bsf wr ;disable write pin on adc
bcf wr ;sets write pin on adc
call delay
call delay
call delay
bsf wr ;disable write pin on adc

wait: btfsc int ;if clear pin is active and coversion ended
goto wait ;if set pin is inactive and conversion not finished
bcf rd ;sets read pin on adc to get digital output code
call delay
call delay
call delay
movf 5,0 ;move digital inputs to working reg.
movwf count ;save digital outputs on 20h
bsf rd ;disable read on adc
return ;return to main program
;-----------------------------------------------------------------------------------------------
;test for 2 volt
;-----------------------------------------------------------------------------------------------

test1: btfss count,1 ;test counter bit1 for set
goto next ;if not set goto next step
btfsc count,0 ;test counter bit0 for clear
goto next ;if not clear goto next step
bsf led_2V ;set led 2 volt if conditions is met
bcf led_3V ;clear led 3 volt if led 2 volt is on
next: nop ;no opperation
return ;return to main program
;-----------------------------------------------------------------------------------------------
;test for 3 volt
;-----------------------------------------------------------------------------------------------

test2: btfss count,1 ;test counter pin1 for set
goto next2 ;if not set goto next2 step
btfss count,0 ;test counter pin0 for set
goto next2 ;if not set goto next2 step
bsf led_3V ;set led 3 volt if conditions is met
bcf led_2V ;clear led 2 volt if led 3 volt is on
next2: nop ;no opperation
return ;return to main program
;-----------------------------------------------------------------------------------------------
;shift serial data to shift reg.
;-----------------------------------------------------------------------------------------------

shift_data: movlw 0x08 ;moves number to working
movwf file1 ;saves number to rotate counter

again: btfss count,0 ;test bit0 on file
bcf sr_data ;gives a zero output into shift
btfsc count,0 ;test bit0 on file
bsf sr_data ;gives a one output into shift

clock: bcf sr_clk ;gives 0 on shift reg. clock pin
bsf sr_clk ;gives 1 on shift reg. clock pin
nop ;no opperation
nop ;no opperation
bcf sr_clk ;gives 0 on shift reg. clock pin

rotate: rrf count,1 ;rotate file one to the right and save to file
decfsz file1,1 ;rotate must be repeated 8 times
goto again ;goto again if not repeated 8 times
return ;return to main program
;-----------------------------------------------------------------------------------------------
;lookup table
;-----------------------------------------------------------------------------------------------

table: movf count,0 ;moves counter to working
call op_table ;call subrotine
movwf count ;moves working reg. to counter file
return ;return to main program

op_table: addwf 2,1 ;saves working to program counter file to make jump
retlw 0x00 ;0000 0000-0- returns number to working
retlw 0x00 ;0000 0001-1
retlw 0x00 ;0000 0010-2
retlw 0x00 ;0000 0011-3
retlw 0x00 ;0000 0100-4
retlw 0x00 ;0000 0101-5
retlw 0x00 ;0000 0110-6
retlw 0x00 ;0000 0111-7
retlw 0x00 ;0000 1000-8
retlw 0x00 ;0000 1001-9
retlw 0x00 ;0000 1010-10
retlw 0x00 ;0000 1011-11
retlw 0x00 ;0000 1100-12
retlw 0x00 ;0000 1101-13
retlw 0x00 ;0000 1110-14
retlw 0x00 ;0000 1111-15
retlw 0x00 ;0001 0000-16
retlw 0x00 ;0001 0001-17
retlw 0x00 ;0001 0010-18
retlw 0x00 ;0001 0011-19
retlw 0x00 ;0001 0100-20
retlw 0x00 ;0001 0101-21
retlw 0x00 ;0001 0110-22
retlw 0x00 ;0001 0111-23
retlw 0x00 ;0001 1000-24
retlw 0x00 ;0001 1001-25
retlw 0x00 ;0001 1010-26
retlw 0x00 ;0001 1011-27
retlw 0x00 ;0001 1100-28
retlw 0x00 ;0001 1101-29
retlw 0x00 ;0001 1110-30
retlw 0x00 ;0001 1111-31
retlw 0x00 ;0010 0000-32
retlw 0x00 ;0010 0001-33
retlw 0x00 ;0010 0010-34
retlw 0x00 ;0010 0011-35
retlw 0x00 ;0010 0100-36
retlw 0x00 ;0010 0101-37
retlw 0x00 ;0010 0110-38
retlw 0x00 ;0010 0111-39
retlw 0x00 ;0010 1000-40
retlw 0x00 ;0010 1001-41
retlw 0x00 ;0010 1010-42
retlw 0x00 ;0010 1011-43
retlw 0x01 ;0010 1100-44
retlw 0x01 ;0010 1101-45
retlw 0x01 ;0010 1110-46
retlw 0x01 ;0010 1111-47
retlw 0x01 ;0011 0000-48
retlw 0x01 ;0011 0001-49
retlw 0x01 ;0011 0010-50
retlw 0x01 ;0011 0011-51
retlw 0x01 ;0011 0100-52
retlw 0x01 ;0011 0101-53
retlw 0x01 ;0011 0110-54
retlw 0x01 ;0011 0111-55
retlw 0x01 ;0011 1000-56
retlw 0x01 ;0011 1001-57
retlw 0x01 ;0011 1010-58
retlw 0x01 ;0011 1011-59
retlw 0x01 ;0011 1100-60
retlw 0x01 ;0011 1101-61
retlw 0x01 ;0011 1110-62
retlw 0x01 ;0011 1111-63
retlw 0x01 ;0100 0000-64
retlw 0x01 ;0100 0001-65
retlw 0x01 ;0100 0010-66
retlw 0x01 ;0100 0011-67
retlw 0x01 ;0100 0100-68
retlw 0x01 ;0100 0101-69
retlw 0x01 ;0100 0110-70
retlw 0x01 ;0100 0111-71
retlw 0x01 ;0100 1000-72
retlw 0x01 ;0100 1001-73
retlw 0x01 ;0100 1010-74
retlw 0x01 ;0100 1011-75
retlw 0x01 ;0100 1100-76
retlw 0x01 ;0100 1101-77
retlw 0x01 ;0100 1110-78
retlw 0x01 ;0100 1111-79
retlw 0x01 ;0101 0000-80
retlw 0x01 ;0101 0001-81
retlw 0x01 ;0101 0010-82
retlw 0x01 ;0101 0011-83
retlw 0x01 ;0101 0100-84
retlw 0x01 ;0101 0101-85
retlw 0x01 ;0101 0110-86
retlw 0x02 ;0101 0111-87
retlw 0x02 ;0101 1000-88
retlw 0x02 ;0101 1001-89
retlw 0x02 ;0101 1010-90
retlw 0x02 ;0101 1011-91
retlw 0x02 ;0101 1100-92
retlw 0x02 ;0101 1101-93
retlw 0x02 ;0101 1110-94
retlw 0x02 ;0101 1111-95
retlw 0x02 ;0110 0000-96
retlw 0x02 ;0110 0001-97
retlw 0x02 ;0110 0010-98
retlw 0x02 ;0110 0011-99
retlw 0x02 ;0110 0100-100
retlw 0x02 ;0110 0101-101
retlw 0x02 ;0110 0110-102
retlw 0x02 ;0110 0111-103
retlw 0x02 ;0110 1000-104
retlw 0x02 ;0110 1001-105
retlw 0x02 ;0110 1010-106
retlw 0x02 ;0110 1011-107
retlw 0x02 ;0110 1100-108
retlw 0x02 ;0110 1101-109
retlw 0x02 ;0110 1110-110
retlw 0x02 ;0110 1111-111
retlw 0x02 ;0111 0000-112
retlw 0x02 ;0111 0001-113
retlw 0x02 ;0111 0010-114
retlw 0x02 ;0111 0011-115
retlw 0x02 ;0111 0100-116
retlw 0x02 ;0111 0101-117
retlw 0x02 ;0111 0110-118
retlw 0x02 ;0111 0111-119
retlw 0x02 ;0111 1000-120
retlw 0x02 ;0111 1001-121
retlw 0x02 ;0111 1010-122
retlw 0x02 ;0111 1011-123
retlw 0x02 ;0111 1100-124
retlw 0x02 ;0111 1101-125
retlw 0x02 ;0111 1110-126
retlw 0x02 ;0111 1111-127
retlw 0x02 ;1000 0000-128
retlw 0x02 ;1000 0001-129
retlw 0x03 ;1000 0010-130
retlw 0x03 ;1000 0011-131
retlw 0x03 ;1000 0100-132
retlw 0x03 ;1000 0101-133
retlw 0x03 ;1000 0110-134
retlw 0x03 ;1000 0111-135
retlw 0x03 ;1000 1000-136
retlw 0x03 ;1000 1001-137
retlw 0x03 ;1000 1010-138
retlw 0x03 ;1000 1011-139
retlw 0x03 ;1000 1100-140
retlw 0x03 ;1000 1101-141
retlw 0x03 ;1000 1110-142
retlw 0x03 ;1000 1111-143
retlw 0x03 ;1001 0000-144
retlw 0x03 ;1001 0001-145
retlw 0x03 ;1001 0010-146
retlw 0x03 ;1001 0011-147
retlw 0x03 ;1001 0100-148
retlw 0x03 ;1001 0101-149
retlw 0x03 ;1001 0110-150
retlw 0x03 ;1001 0111-151
retlw 0x03 ;1001 1000-152
retlw 0x03 ;1001 1001-153
retlw 0x03 ;1001 1010-154
retlw 0x03 ;1001 1011-155
retlw 0x03 ;1001 1100-156
retlw 0x03 ;1001 1101-157
retlw 0x03 ;1001 1110-158
retlw 0x03 ;1001 1111-159
retlw 0x03 ;1010 0000-160
retlw 0x03 ;1010 0001-161
retlw 0x03 ;1010 0010-162
retlw 0x03 ;1010 0011-163
retlw 0x03 ;1010 0100-164
retlw 0x03 ;1010 0101-165
retlw 0x03 ;1010 0110-166
retlw 0x03 ;1010 0111-167
retlw 0x03 ;1010 1000-168
retlw 0x03 ;1010 1001-169
retlw 0x03 ;1010 1010-170
retlw 0x03 ;1010 1011-171
retlw 0x03 ;1010 1100-172
retlw 0x04 ;1010 1101-173
retlw 0x04 ;1010 1110-174
retlw 0x04 ;1010 1111-175
retlw 0x04 ;1011 0000-176
retlw 0x04 ;1011 0001-177
retlw 0x04 ;1011 0010-178
retlw 0x04 ;1011 0011-179
retlw 0x04 ;1011 0100-180
retlw 0x04 ;1011 0101-181
retlw 0x04 ;1011 0110-182
retlw 0x04 ;1011 0111-183
retlw 0x04 ;1011 1000-184
retlw 0x04 ;1011 1001-185
retlw 0x04 ;1011 1010-186
retlw 0x04 ;1011 1011-187
retlw 0x04 ;1011 1100-188
retlw 0x04 ;1011 1101-189
retlw 0x04 ;1011 1110-190
retlw 0x04 ;1011 1111-191
retlw 0x04 ;1100 0000-192
retlw 0x04 ;1100 0001-193
retlw 0x04 ;1100 0010-194
retlw 0x04 ;1100 0011-195
retlw 0x04 ;1100 0100-196
retlw 0x04 ;1100 0101-197
retlw 0x04 ;1100 0110-198
retlw 0x04 ;1100 0111-199
retlw 0x04 ;1100 1000-200
retlw 0x04 ;1100 1001-201
retlw 0x04 ;1100 1010-202
retlw 0x04 ;1100 1011-203
retlw 0x04 ;1100 1100-204
retlw 0x04 ;1100 1101-205
retlw 0x04 ;1100 1110-206
retlw 0x04 ;1100 1111-207
retlw 0x04 ;1101 0000-208
retlw 0x04 ;1101 0001-209
retlw 0x04 ;1101 0010-210
retlw 0x04 ;1101 0011-211
retlw 0x04 ;1101 0100-212
retlw 0x04 ;1101 0101-213
retlw 0x04 ;1101 0110-214
retlw 0x04 ;1101 0111-215
retlw 0x05 ;1101 1000-216
retlw 0x05 ;1101 1001-217
retlw 0x05 ;1101 1010-218
retlw 0x05 ;1101 1011-219
retlw 0x05 ;1101 1100-220
retlw 0x05 ;1101 1101-221
retlw 0x05 ;1101 1110-222
retlw 0x05 ;1101 1111-223
retlw 0x05 ;1110 0000-224
retlw 0x05 ;1110 0001-225
retlw 0x05 ;1110 0010-226
retlw 0x05 ;1110 0011-227
retlw 0x05 ;1110 0100-228
retlw 0x05 ;1110 0101-229
retlw 0x05 ;1110 0110-230
retlw 0x05 ;1110 0111-231
retlw 0x05 ;1110 1000-232
retlw 0x05 ;1110 1001-233
retlw 0x05 ;1110 1010-234
retlw 0x05 ;1110 1011-235
retlw 0x05 ;1110 1100-236
retlw 0x05 ;1110 1101-237
retlw 0x05 ;1110 1110-238
retlw 0x05 ;1110 1111-239
retlw 0x05 ;1111 0000-240
retlw 0x05 ;1111 0001-241
retlw 0x05 ;1111 0010-242
retlw 0x05 ;1111 0011-243
retlw 0x05 ;1111 0100-244
retlw 0x05 ;1111 0101-245
retlw 0x05 ;1111 0110-246
retlw 0x05 ;1111 0111-247
retlw 0x05 ;1111 1000-248
retlw 0x05 ;1111 1001-249
retlw 0x05 ;1111 1010-250
retlw 0x05 ;1111 1011-251
retlw 0x05 ;1111 1100-252
retlw 0x05 ;1111 1101-253
retlw 0x05 ;1111 1110-254
retlw 0x05 ;1111 1111-255
;-----------------------------------------------------------------------------------------------
;delay
;-----------------------------------------------------------------------------------------------

delay: movlw 0xff ;loads 255 to working
movwf 40h ;saves number to file
loop2: movlw 0xff ;loads 255 to working
movwf 41h ;saves number to file
loop1: decfsz 41h,1 ;decrement file until zero saves outcome to file
goto loop1 ;if not zero keep decrementing
decfsz 40h,1 ;decrement file until zero saves outcome to file
goto loop2 ;if not zero keep decrementing
return ;return to main program
;------------------------------------------------------------------------------------------------
end
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…