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.

PIC 16F877A Problem Please help

Status
Not open for further replies.

Shadi Ghabboun

Newbie level 3
Joined
Apr 12, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,385
hey guys
how are you all ?
am making a digital voltmeter so everything works as i want except that when i want to show the value under the range ( we first put "Range:0-10" for example and then find the value) nothing appears but if we want to show it beside the range no problems at all

we are doing this code with assembly so what ive been doing is adding
movlw b'11000000'
call send_cmd (send_cmd is my command sender subroutine)
is there anything wrong

so if anyone has an idea or can help me i would be very thankful
Best Regards


Note:i didnt post the prog coz its very long if anyone care to read just tell me thanks
 

Post your code. What do you mean by Range 0 - 10?



thanks for your reply
here is the code




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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#include "p16f877a.inc"
 
  
 
        cblock          0x20    
                                lsd                 ;lsd and msd are used in delay loop calculation
                                msd     
                temp 
                temp1
                temp2
                temp3
                ones
                units
                tens
                hundreds
                count1
                TEMP
        endc
;**************************************************
    ORG  0X000
    GOTO Main
    ORG  0X004
    GOTO ISR
 
 
 
;*************************************************** 
Main
        Banksel INTCON
        BCF     INTCON,GIE      ; interrupts are disabled
       call initial
       GOTO Welcome
      
 
 
 
;****************************************************
 
 
 
initial
        Banksel TRISA           
                movlw   b'00100011'     ; RA0, RA1, RA5 are input
        movwf   TRISA           
                Clrf    TRISD
        Banksel TRISE           ; PORTE is output
        Clrf    TRISE
        Banksel TRISB
        movlw   b'11110000'     ; RB7, RB6, RB5, RB4 are input
        movwf   TRISB   
        Banksel PORTB
        clrf    PORTB
        Banksel TRISC
        clrf    TRISC
        Banksel PORTC
        clrf    PORTC
        clrf    tens
        clrf    units
        Banksel  ADCON1
                movlw   b'00000010'             ;set pin 0,1,5 of PORTA as analog input & the result is left justified     
                movwf   ADCON1  
                Banksel PORTA
                Clrf    PORTA           
                Clrf    PORTD
        Clrf    tens
        Clrf    ones
        Banksel INTCON
        bcf     INTCON,RBIF
        bsf     INTCON,RBIE
        ;LCD Initialization
        Movlw   0x38            ;8-bit mode, 2-line display, 5x7 dot format
                Call    send_cmd        
                Movlw   0x0e            ;Display on, Cursor Underline on, Blink off
                Call    send_cmd
                Movlw   0x02            ;Display and cursor home
                Call    send_cmd
                Movlw   0x01                ;clear display
                Call    send_cmd 
 
       
 
       
        
 return
 
 
  
 ;**********************************************
Welcome                   ;  Welcome To DVM!
         movlw 0x57
         call  send_char
         movlw 0x65
         call  send_char
         movlw 0x6C
         call  send_char
         movlw 0x63
         call  send_char
         movlw 0x6F
         call  send_char
         movlw 0x6D
         call  send_char
         movlw 0x65
         call  send_char
         movlw 0x20
         call  send_char
         movlw 0x54
         call  send_char
         movlw 0x6F
         call  send_char
         movlw 0x20
         call  send_char
         movlw 0x44
         call  send_char
         movlw 0x56
         call  send_char
         movlw 0x4D
         call  send_char
         movlw 0x21
         call  send_char
   
         call delay
         call delay
         call delay
         call delay
         call delay
         call delay
     call delay
         call delay
         call delay
         call delay
         call delay
         call delay
     call delay
         call delay
         call delay
         call delay
         call delay
 
        Movlw   0x02              ;Display and cursor home
    Call        send_cmd
        Movlw   0x01              ;clear display
        Call    send_cmd 
 
    Banksel INTCON
    BSF     INTCON,GIE
    BSF     INTCON,RBIE
    BCF     INTCON,RBIF
    
   
wait 
   goto  wait
;**********************************************
ISR
    call    delay
   
    
    Banksel INTCON
    ;bcf     INTCON,GIE
    btfsc PORTB,4          ; check the interrupt source
    GOTO  range_5
    btfsc PORTB,5
    GOTO  range_10
    btfsc PORTB,6
    GOTO  range_15
    Movlw       0x02              ; Display and cursor home
    Call        send_cmd
        Movlw   0x01          ; clear display
        Call    send_cmd  
    BANKSEL  INTCON
    BCF      INTCON,GIE
    SLEEP     
    MOVF   PORTB,0
 
    bcf   INTCON,RBIF
    BSF     INTCON,GIE
    MOVF   PORTB,0
 
    
ret 
MOVF   PORTB,0
BCF    INTCON,RBIF
 RETFIE
;*********************************************
TABLE
     addwf  PCL,1
     RETLW  0X30        ; "0"
     RETLW  0X31        ; "1"
     RETLW  0X32        ; "2"
     RETLW  0X33        ; "3"
     RETLW  0X34        ; "4"
     RETLW  0X35        ; "5"
     RETLW  0X36        ; "6"
     RETLW  0X37        ; "7"
     RETLW  0X38        ; "8"
     RETLW  0X39        ; "9"
 
;**********************************************
 
 
 
;**********************************************
CHANGE_To_BCD
gen_hunds
                MOVLW     .100             ;sub 100,result keep in W
            SUBWF     TEMP,0
                BTFSS     STATUS,C         ;judge if the result biger than 100
                GOTO      gen_tens         ;no,get the ten bit result
                MOVWF     TEMP             ;yes,result keep in TEMP
                INCF      hundreds,1       ;hundred bit add 1
                GOTO      gen_hunds        ;continue to get hundred bit result
gen_tens
                MOVLW     .10              ;sub 10,result keep in W
                SUBWF     TEMP,0          
                BTFSS     STATUS,C         ;judge if the result bigger than 10
                GOTO      gen_ones         ;no,get the Entries bit result
                MOVWF     TEMP             ;yes,result keep in TEMP
                INCF      tens,1           ;ten bit add 1
                GOTO      gen_tens         ;turn  to continue get ten bit
gen_ones
                MOVF      TEMP,W
                MOVWF     units            ;the value of Entries bit
                RETURN
        
;**********************************************
Display
  MOVF     hundreds,W              ;display Tens bit
  CALL     TABLE
  CALL     send_char
  
  
  MOVF     tens,W                  ;display Units bit
  CALL     TABLE
  CALL     send_char
  
 
  movlw    0x2E                    ; display the dot
  call     send_char
 
  MOVF     units,W                  ;display fraction bit
  CALL     TABLE
  CALL     send_char 
  
  RETURN
 ;**********************************************
 
Out_Of_Range
 
    bsf     PORTC,0               ; BUZZER ON
 
        Movlw   0x02                  ;Display and cursor home
    Call        send_cmd
        Movlw   0x01                      ;clear display
        Call    send_cmd 
 
    movlw 0x4F                    ; display "out of range"
    call  send_char
    movlw 0x75
    call  send_char
    movlw 0x74
    call  send_char
    movlw 0x20
    call  send_char
    movlw 0x4F
    call  send_char
    movlw 0x66
    call  send_char
    movlw 0x20
    call  send_char
    movlw 0x52
    call  send_char
    movlw 0x61
    call  send_char
    movlw 0x6E
    call  send_char
    movlw 0x67
    call  send_char
    movlw 0x65
    call  send_char
 
    ;BANKSEL  INTCON
    ;BSF      INTCON,GIE
 
 
 goto   ret
 
;**************************************************
 send_cmd
                movwf   PORTD                   
                bcf     PORTE,  0                                                                                 
                bsf     PORTE,  2               
                nop                             
                bcf     PORTE,  2
                bcf     PORTE,  1               
                call    delay                   
                return
;**************************************************
send_char
                movwf   PORTD   
                bsf     PORTE,  0                
                bsf     PORTE,  2                               
                nop
                bcf     PORTE,  2
                bcf     PORTE,  1
                call    delay
                return
;**************************************************
range_5
    BANKSEL INTCON
    BCF   INTCON,GIE
    bcf   PORTC,0          ; turn buzzer off
    
    clrw
    clrf  temp1            ; clear the registers used in calculation
    clrf  temp2
    clrf  temp3
    clrf  TEMP
    clrf  hundreds
    clrf  tens
    clrf  units
 
    Banksel ADCON0         ; ADC on, select channel 0(AN0)
    movlw   b'01000001'
    movwf   ADCON0
    Banksel INTCON
    BCF     INTCON,RBIF
   
    Banksel PORTB
    bcf     PORTB,4
        Movlw   0x02               ; Display and cursor home
    Call        send_cmd
        Movlw   0x01           ; clear display
        Call    send_cmd 
 
    movlw 0x52             ; display range
    call  send_char
    movlw 0x61
    call  send_char
    movlw 0x6E
    call  send_char
    movlw 0x67
    call  send_char
    movlw 0x65
    call  send_char
    movlw 0x3A
    call  send_char
    movlw 0x20
    call  send_char
    movlw 0x30
    call  send_char
    movlw 0x2D
    call  send_char
    movlw 0x35
    call  send_char
 
        movlw   0x20
        call    send_char
        
        
   
    ;movlw b'11000000'       ; skip line
    ;call  send_cmd
   
   
    
   
    CALL        delay
        BSF     ADCON0,GO       ; startup ADC conversion
WAIT
        BTFSS   PIR1,ADIF       ; Is the conversion done?
        GOTO    WAIT            ; wait conversion to be finished
        bcf     PIR1, ADIF      ; Clear the A/D flag
        Banksel ADRESH
        MOVF    ADRESH,W        ; read the result of conversion
    movwf   temp1       
    movwf   temp2
    movwf   temp3
    banksel STATUS
    BCF     STATUS,C
    RRF     temp1,1         ; ADRESH/2
    bcf     STATUS,C
    RRF     temp2,1         ; ADRESH/16
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp3,1         ; ADRESH/32
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
 
    movf   temp1,0
    addwf  temp2,0
    addwf  temp3,1   
    movlw  .50
    subwf   temp3,0          ; check if the result is within the selected range
    
    btfsc  STATUS,C
    goto   Out_Of_Range
    movf   temp3,0
    movwf  TEMP
   
 
    call    CHANGE_To_BCD
    call    delay
    call    delay
        call    Display
    banksel INTCON
    MOVF   PORTB,0
    bcf     INTCON,RBIF
    BSF     INTCON,GIE
 
    goto    ret
    
     
;***********************************************
 
range_10
    BANKSEL INTCON
    BCF   INTCON,GIE
    bcf     PORTC,0        ; turn buzzer off
 
    clrw
    clrf  temp1            ; clear the registers used in calculation
    clrf  temp2
    clrf  temp3
    clrf  TEMP
    clrf  hundreds
    clrf  tens
    clrf  units
 
   
   
    Banksel PORTB
    BCF     PORTB,5
        Movlw   0x02              ; Display and cursor home
    Call        send_cmd
        Movlw   0x01          ; clear display
        Call    send_cmd  
 
    movlw 0x52            ; display range
    call  send_char 
    movlw 0x61
    call  send_char
    movlw 0x6E
    call  send_char
    movlw 0x67
    call  send_char
    movlw 0x65
    call  send_char
    movlw 0x3A
    call  send_char
    movlw 0x20
    call  send_char
    movlw 0x30
    call  send_char
    movlw 0x2D
    call  send_char
    movlw 0x31
    call  send_char
    movlw 0x30
    call  send_char
 
        movlw   0x20
        call    send_char
 
    ;movlw b'11000000'       ; skip line
    ;call  send_cmd
 
 
   
 
    
 
    Banksel ADCON0          ; ADC on, select channel 1(AN1)
    movlw   b'01001001'
    movwf   ADCON0
 
    CALL        delay
        BSF     ADCON0,GO       ; startup ADC conversion
WAIT2
        BTFSS   PIR1,ADIF       ; Is the conversion done?
        GOTO    WAIT2           ; wait conversion to be finished
        bcf     PIR1, ADIF          ; Clear the A/D flag
        Banksel ADRESH
        MOVF    ADRESH,W        ; read the result of conversion
    movwf   temp1       
    movwf   temp2
    movwf   temp3
    banksel STATUS
    BCF     STATUS,C
    RRF     temp1,1         ; ADRESH/2
    bcf     STATUS,C
    RRF     temp2,1         ; ADRESH/16
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp3,1         ; ADRESH/32
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
 
    movf   temp1,0
    addwf  temp2,0
    addwf  temp3,1
    movlw  .100
    subwf   temp3,0          ;  check if the result is within the selected range
    
    btfsc  STATUS,C
    goto   Out_Of_Range
    movf   temp3,0
    movwf  TEMP
   
 
    call    CHANGE_To_BCD
    call    delay
    call    delay
        call    Display
    banksel INTCON
    MOVF   PORTB,0
    BCF     INTCON,RBIF
    BSF     INTCON,GIE
 
    goto    ret
 
;*********************************************
range_15
    bcf     PORTC,0         ;turn buzzer off
 
    BANKSEL INTCON
    BCF   INTCON,GIE
    clrw
    clrf  temp1             ; clear the registers used in calculation
    clrf  temp2
    clrf  temp3
    clrf  TEMP
    clrf  hundreds
    clrf  tens
    clrf  units
 
   
   
    Banksel PORTB
    BCF     PORTB,6
        Movlw   0x02            ;Display and cursor home
    Call        send_cmd
        Movlw   0x01                ;clear display
        Call    send_cmd 
 
    movlw 0x52              ; display range
    call  send_char
    movlw 0x61
    call  send_char
    movlw 0x6E
    call  send_char
    movlw 0x67
    call  send_char
    movlw 0x65
    call  send_char
    movlw 0x3A
    call  send_char
    movlw 0x20
    call  send_char
    movlw 0x30
    call  send_char
    movlw 0x2D
    call  send_char
    movlw 0x31
    call  send_char
    movlw 0x35
    call  send_char
    
    movlw       0x20
        call    send_char
 
        ;movlw b'11000000'        ; skip line
    ;call  send_cmd
 
   
 
    Banksel ADCON0           ; ADC on, select channel 4(AN4)
    movlw   b'01100001'
    movwf   ADCON0
 
    CALL        delay
        BSF     ADCON0,GO            ;startup ADC divert
WAIT3
        BTFSS   PIR1,ADIF        ;Is the conversion done?
        GOTO    WAIT3            ; wait conversion to be finished
        bcf     PIR1, ADIF       ; Clear the A/D flag
        Banksel ADRESH
        MOVF    ADRESH,W             ;read the result of conversion
    movwf   temp1       
    movwf   temp2
    movwf   temp3
    banksel STATUS
    BCF     STATUS,C
    RRF     temp1,1          ; ADRESH/2
    bcf     STATUS,C
    RRF     temp2,1          ; ADRESH/16
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp2,1
    bcf     STATUS,C
    RRF     temp3,1          ; ADRESH/32
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
    bcf     STATUS,C
    RRF     temp3,1
 
    movf   temp1,0
    addwf  temp2,0
    addwf  temp3,1
    movlw  .149               
    subwf   temp3,0           ; check if the result is within the selected range    
    
    btfsc  STATUS,C
    goto   Out_Of_Range
    movf   temp3,0
    movwf  TEMP
   
 
    call    CHANGE_To_BCD
    call    delay
    call    delay
        call    Display
    banksel INTCON
    MOVF   PORTB,0
    BCF     INTCON,RBIF
    BSF     INTCON,GIE
 
    goto    ret
 
delay                                                                                   
                movlw   0x40                    
                movwf   msd
                clrf    lsd
loop2
                decfsz  lsd,f
                goto    loop2
                decfsz  msd,f
endLcd
                goto    loop2
                return
 
end




as for your question .... i have 3 ranges 0-5 , 0-10 & 0-15 so what the program have to do is to put the range and under it the value but it does not work but if i put the value beside the range then it works ( if u changed lines 355&356 by 360& 361 the result wont appear if u leave it as is it works great) and btw the program works great on proteus

Regards
 

Hi,

Can you post your .dsn so we can see it running.

You can make life / your code easier if you use the ascii character rather than a hex or binary value
movlw 0x20
call send_char

Code:
movlw ' ' 
 call    send_char
movlw 'V'
 call    send_char
movlw '9'
 call    send_char

Also your code variables have 2 registers with the same name 'temp' and 'TEMP' not good practice.
There is a build option to enable or disable case sensitivity, if its on it gives a build error.
 

thanks for your reply

as for the DSN file u can get it here ( could upload is here)
**broken link removed**

as for the ascii you are right but its a project and they asked to do it with hex or binary so i cant use other (its stupid i know but all for the grade :D)

and btw in protues it works both ways but on the pic it self it does not work only one way

Best Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top