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] Im not sure why my program is not working..

Status
Not open for further replies.

haqeemnasir

Newbie level 2
Joined
Feb 21, 2017
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
26
Hello everyone, im currently working on my own project. Below is my program. PORTC works fine..but im not sure why PORTA are not working. in this program, when the user press the button(PORTA and PORTC), the BCD 7 segment display will increase by 1. the button are active low. i also attach the schematic diagram..


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
#include<p18F4550.inc>
 
k set 0x01
a set 0x02
b set 0x03
c set 0x04
d set 0x05
e set 0x06
f set 0x07
g set 0x08
 
org 0x00
goto start
org 0x08
retfie
org 0x18
retfie
 
start   clrf TRISD,A
                setf TRISC,A
                setf TRISA,A
                clrf PORTD,A
                clrf PORTC,A
                clrf PORTA,A
                movlw 0x02
                movwf a
                movwf b
                movwf c
                movwf d
                movwf e
                movwf f
                movwf g
 
check   btfsc PORTC,0,A ;user1
                bra here
                btfss PORTC,0,A
                bra check
                call person1
 
here    btfsc PORTC,1,A ;user2
                bra check1
                btfss PORTC,1,A
                bra here
                call person2
 
check1  btfsc PORTC,2,A ;user3
                bra check
                btfss PORTC,2,A
                bra check1
                call person3
                
check2  btfsc PORTA,0,A ;user4
                bra check
                btfss PORTA,0,A
                bra check2
                call person4
 
check3  btfsc PORTA,1,A ;user5
                bra check
                btfss PORTA,1,A
                bra check3
                call person5
 
check4  btfsc PORTA,2,A ;user6
                bra check
                btfss PORTA,2,A
                bra check4
                call person6
 
check5  btfsc PORTA,3,A ;user7
                bra check
                btfss PORTA,3,A
                bra check5
                call person7
 
                bra check
 
person1 decfsz a
                call inc
                return
 
person2 decfsz b
                call inc
                return
 
person3 decfsz c
                call inc
                return
 
person4 decfsz d
                call inc
                return
 
person5 decfsz e
                call inc
                return
 
person6 decfsz f
                call inc
                return
 
person7 decfsz g
                call inc
                return
 
inc             incf k
                movff k,PORTD
                return
 
end

 

Attachments

  • ice_screenshot_20170221-090305.png
    ice_screenshot_20170221-090305.png
    13.6 KB · Views: 62
Last edited by a moderator:

PORTA has many of the pins capable of being used as analog inputs. Such pins are set to 'analog' mode by default.
PORTC however does not have analog-capable pins and so are in digital mode by default.
Read up on the ADCON1 register in the data sheet.
Also you should be writing to the LATx registers and not the PORTx ones. The golden rule for devices with LAT registers is to "read from the PORT and write to the LAT".
Susan
 

Clear "ANSELA" register. It will make PORTA as digital I/O only.
 

Clear "ANSELA" register. It will make PORTA as digital I/O only.
The OP shows that he is using a PIC18F4550 (according to the include file at the start of the code snippet that is shown). The PIC18F4550 is one of the "older-style" MCUs that uses the ADCONx registers to control the analog/digital mode of the pins.
The alternate register names that are used by some families and devices have names such as ADxPCFGn and the later ones use the ANSELx convention.
While the use of analog/digital (with a default of analog) is common across many of the Microchip MCUs, you *must* look at the data sheet for the device you are using to see which scheme is used and what the actual settings are (confusingly some have 0 as digital and others have 1).
Susan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top