What are these pins for?

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
I'm working on trying to understand PIC architecture and assembly language, and having a heck of a time I might add.

I've been working on this project for a while using a schematic I've heavily modified from the original schematic, though the pin connections are the same to the PIC.

The end result is essentially an array of LEDs flashing alternately, much like police/fire type LED lights. Here is what I understand regarding the connections to the PIC pins:

PIC is 16F628A

Pin 4, MCLR is connected to +5V through a resistor (I kinda get this)
Pin 5, Vss to ground (gotta have ground, ok, I get that)
Pin 6, RB0 to MOSFET and Ground (output controlling flashes)
Pin 7, RB1 to MOSFET and Ground (same as above)
Pin 14, Vdd voltage in (I get it)
Pins 15 and 16 to crystal for timing (I get it)

What I'm confused over, are pins 17 and 18 RA0/AN0, RA1/AN1 respectively. Why make these connections? Are they being used as an I/O or analog comparators? Can someone explain why these are set up this way?
 

jpanhalt

Joined Jan 18, 2008
11,087
Another option is that the original designer simply tied them high by analogy with CMOS logic. That is not necessary for the PICs, particularly when you set them as outputs.

Also, Microchip recommends a small capacitor from MCLR to ground so that resetting is prevented even if V+ dips. See the datasheet.

What values for R3 and R4 are suggested?

John
 

S_lannan

Joined Jun 20, 2007
246
i was under the same impression.
the pic16f628a does indeed have comparators.
CMCON = 7 would turn them off.
i can only assume where alberto said CMCOM = 7 was just a typographical error.
 

S_lannan

Joined Jun 20, 2007
246
What I'm confused over, are pins 17 and 18 RA0/AN0, RA1/AN1 respectively. Why make these connections? Are they being used as an I/O or analog comparators? Can someone explain why these are set up this way?

Now when you said you have heavily modified the schematic, did you modify any parts of the circuit that connects to these pins?

Post the source code too, we may be able to answer some questions regarding what is confusing you about the programming of the pic.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Let's dive a little deeper into what I'm doing.

I had an interest in building emergency style lighting, its something of a passion (where the majority of my electrical interests lie). I found a schematic that included a .hex file. The original schematic didn't work for me, so with help from the members here, the schematic was modified to the point where it works quite well to the best of my knowledge (as in it does what it's supposed to and nothing gets real hot). The only thing that gets remotely hot is the LM7809 which provides 9V to the LED arrays. I plan to include room in the future for a heat sink for that component.

Through this entire process, the .hex code has remained the same. My goal now is to learn assembly so I can design my own code, preferably a program that can store/use multiple led flash patterns that you can change by pressing a momentary switch, must like most commercial emergency warning lights available.

THIS page is where I found the ORIGINAL schematic and the downloadable .hex file. I don't know what to do with a .hex file in order to "look at the software". .hex files are gibberish to me and I'm not sure about using a disassembler. And at this point, assembly still confuses me quite a bit, although I admit I'm starting to grasp some things. I'm reading a lot. The .hex file is on this page though, if you know how to look at it.

Now when you said you have heavily modified the schematic, did you modify any parts of the circuit that connects to these pins?
Yes, mostly to upgrade parts to handle more than 2 LEDs (my circuit has 60 of them). All part replacements were based on suggestions from members of AAC. My first thread showing suggestions from members and some project progress can be viewed on THIS THREAD.

Presumably, R5 and R6 are relatively low value, such as 100 to 200 ohm?
Both are 200Ω yes.

My entire project including parts list can be found in the attached .pdf

Thank you for all your help.
 

BMorse

Joined Sep 26, 2009
2,675
From what I can see in regards to the schematics (if indeed the hex code has not changed from what you downloaded from the site) it looks like the original designer used those pins possibly as digital inputs, he has them pulled low with 10k resistors when the switch is open and they go high when the switch is closed (the switch has nothing to do with powering the pic, the pic is powered regardless of switch position, I'm just mentioning this in case someone was thinking that was a power switch ;)~). Why he has them both tied together is another thing. Have you tried to wire those pins exactly as they are shown??
Maybe it is to switch to a different pattern of flashing lights??
I do not have a 628A available at the moment or I would try it out :( ....

Just My .02
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Thanks for the reply on that, glad someone looked into it and I appreciate it. The only time I tried the schematic exactly as it was shown, particularly in reference to those two pins where you ask
Have you tried to wire those pins exactly as they are shown??
is when I built the device the first time and then asked for input here when I could not get the thing to operate.

It was suggested to me a while back:

there is also doubt why he uses two 10K resistors on a single node at Pin#17 & #18. I think you can use just one 10K instead.
I will throw one together on a breadboard again and see what happens.

Any other input from anyone else would still be helpful if there's another opinion.
 

jpanhalt

Joined Jan 18, 2008
11,087
I don't understand the 10K resistor stuff with respect to the original schematic. That schematic shows pins 17 & 18 pulled hard high. There is a resistor to ground -- its purpose is unknown to me.

In any event, if you pull 17 & 18 hard high you should not use them as outputs. Check the datasheet. It specifically cautions against driving an output pin high or low with an external circuit due to excessive current. Of course, if your program sets the pins high and keeps them there, there may be no harm, but why risk it. I doubt they are being used as inputs, as they will always be high.

Can you post the disassembled program?

John
 

BMorse

Joined Sep 26, 2009
2,675
I don't understand the 10K resistor stuff with respect to the original schematic. That schematic shows pins 17 & 18 pulled hard high. There is a resistor to ground -- its purpose is unknown to me.

In any event, if you pull 17 & 18 hard high you should not use them as outputs. Check the datasheet. It specifically cautions against driving an output pin high or low with an external circuit due to excessive current. Of course, if your program sets the pins high and keeps them there, there may be no harm, but why risk it. I doubt they are being used as inputs, as they will always be high.

Can you post the disassembled program?

John

If you look at the original schematic, those inputs are held low by the 10K resistors, they will only go high when you close the switch, In his new schematic, it does show them as being held high all the time.
 

jpanhalt

Joined Jan 18, 2008
11,087
Not quite sure about that other original schematic . I was referring to the original version that was attached to post #1 of this thread. They are attached directly to IC2 output there.

John
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Can you post the disassembled program?
I wish I could, I'd like to look at it myself. I can't find a disassembler that works for me. I'm still new at working with code/software.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
I rebuilt the device on the breadboard with pins 17 & 18 wired from 5V source through a switch. With switch closed, the device works normally. With the switch open, the device does nothing. I have no idea why the original designer did that.
 

jpanhalt

Joined Jan 18, 2008
11,087
I have attached a disassembled version. My disassembler did not have 16F628A, so I used 16F628. Caution, I have very little experience doing disassembly and interpreting it. This part of the code looks relevant:
Rich (BB code):
h_002a:
        bcf     portb,rb0                       ;0x06,0 ;002a 1006
        bcf     portb,rb1                       ;0x06,1 ;002b 1086
        btfsc   porta,ra0                       ;0x05,0 ;002c 1805
        goto    h_0031                                  ;002d 2831
        btfsc   porta,ra1                       ;0x05,1 ;002e 1885
        goto    h_0031                                  ;002f 2831
        goto    h_002a                                  ;0030 282a
RA0 and RA1 are pins 17 and 18, respectively. The first BTFSC checks to see if pin 17 is clear (low), if it is low, then it checks RA1 (pin 18). If that is low, it keeps checking both pins. If either is set (high), the program goes to h_0031. The zipped file shows what it does after that.

These pins seem to be used together as an on/off switch. But, they are hardwired together, so I don't understand why the program was designed to check both. For fun, I would disconnect pin 17 and tie it low through a 10K resistor, just to see what happens. If you need those pins for some other purpose, this disassembled program could be used to make appropriate changes.

Hopefully, these comments will stimulate more discussion.

John
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
.hex file disassembled as well... not sure if this is how it's supposed to look, it's my first attempt at a disassembler:

Rich (BB code):
#==========Mode:MPASM Assembler
        include        ""
Reg_003        EQU        H'0003'
Reg_005        EQU        H'0005'
Reg_006        EQU        H'0006'
Reg_01F        EQU        H'001F'
Reg_020        EQU        H'0020'
Reg_021        EQU        H'0021'
Reg_022        EQU        H'0022'
Reg_023        EQU        H'0023'
Reg_026        EQU        H'0026'
Reg_027        EQU        H'0027'
Reg_028        EQU        H'0028'


        ORG        H'00000'
        GOTO        Label_00009

Label_00001
        CLRF        Reg_023
        MOVWF        Reg_022

Label_00002
        MOVLW        H'00FF'
        ADDWF        Reg_022,1
        BTFSS        Reg_003,0
        ADDWF        Reg_023,1
        BTFSS        Reg_003,0
        GOTO        Label_00008
        MOVLW        H'0003'
        MOVWF        Reg_021
        MOVLW        H'00DF'
        CALL        Label_00003
        GOTO        Label_00002
        CLRF        Reg_021

Label_00003
        ADDLW        H'00E8'
        MOVWF        Reg_020
        COMF        Reg_021,1
        MOVLW        H'00FC'
        BTFSS        Reg_003,0
        GOTO        Label_00005

Label_00004
        ADDWF        Reg_020,1
        BTFSC        Reg_003,0
        GOTO        Label_00004

Label_00005
        ADDWF        Reg_020,1
        NOP        
        INCFSZ        Reg_021,1
        GOTO        Label_00004
        BTFSC        Reg_020,0
        GOTO        Label_00006

Label_00006
        BTFSS        Reg_020,1
        GOTO        Label_00007
        NOP        
        GOTO        Label_00007
Label_00007
        RETURN        


Label_00008
        BCF        Reg_003,7
        BCF        Reg_003,5
        BCF        Reg_003,6
        NOP        
        RETURN        

Label_00009
        MOVLW        H'0007'
        MOVWF        Reg_01F

Label_00010
        BCF        Reg_006,0
        BCF        Reg_006,1
        BTFSC        Reg_005,0
        GOTO        Label_00011
        BTFSC        Reg_005,1
        GOTO        Label_00011
        GOTO        Label_00010

Label_00011
        BSF        Reg_005,0
        CLRF        Reg_027

Label_00012
        MOVLW        H'0004'
        SUBWF        Reg_027,0
        BTFSC        Reg_003,0
        GOTO        Label_00017
        CLRF        Reg_026

Label_00013
        MOVLW        H'0007'
        SUBWF        Reg_026,0
        BTFSC        Reg_003,0
        GOTO        Label_00014
        MOVLW        H'0001'
        XORWF        Reg_006,1
        BSF        Reg_003,5
        BCF        Reg_006,0
        MOVLW        H'0032'
        BCF        Reg_003,5
        CALL        Label_00001
        BTFSS        Reg_005,0
        GOTO        Label_00010
        INCFSZ        Reg_026,1
        GOTO        Label_00013

Label_00014
        BCF        Reg_006,0
        CLRF        Reg_026

Label_00015
        MOVLW        H'0007'
        SUBWF        Reg_026,0
        BTFSC        Reg_003,0
        GOTO        Label_00016
        MOVLW        H'0002'
        XORWF        Reg_006,1
        BSF        Reg_003,5
        BCF        Reg_006,1
        MOVLW        H'0032'
        BCF        Reg_003,5
        CALL        Label_00001
        BTFSS        Reg_005,0
        GOTO        Label_00010
        INCFSZ        Reg_026,1
        GOTO        Label_00015

Label_00016
        BCF        Reg_006,1
        INCFSZ        Reg_027,1
        GOTO        Label_00012

Label_00017
        CLRF        Reg_028

Label_00018
        MOVLW        H'0007'
        SUBWF        Reg_028,0
        BTFSC        Reg_003,0
        GOTO        Label_00023
        CLRF        Reg_026

Label_00019
        MOVLW        H'0002'
        SUBWF        Reg_026,0
        BTFSC        Reg_003,0
        GOTO        Label_00020
        MOVLW        H'0001'
        XORWF        Reg_006,1
        BSF        Reg_003,5
        BCF        Reg_006,0
        MOVLW        H'0032'
        BCF        Reg_003,5
        CALL        Label_00001
        BTFSS        Reg_005,0
        GOTO        Label_00010
        INCFSZ        Reg_026,1
        GOTO        Label_00019

Label_00020
        BCF        Reg_006,0
        CLRF        Reg_026

Label_00021
        MOVLW        H'0002'
        SUBWF        Reg_026,0
        BTFSC        Reg_003,0
        GOTO        Label_00022
        MOVLW        H'0002'
        XORWF        Reg_006,1
        BSF        Reg_003,5
        BCF        Reg_006,1
        MOVLW        H'0032'
        BCF        Reg_003,5
        CALL        Label_00001
        BTFSS        Reg_005,0
        GOTO        Label_00010
        INCFSZ        Reg_026,1
        GOTO        Label_00021

Label_00022
        BCF        Reg_006,1
        INCFSZ        Reg_028,1
        GOTO        Label_00018

Label_00023
        GOTO        Label_00011
        GOTO        Label_00010

Label_00024
        SLEEP        
        GOTO        Label_00024

        ORG        H'02007'
        DE        11,10
        END
 

jpanhalt

Joined Jan 18, 2008
11,087
The corresponding section in your listing is Label_00010. Take a look at the disassembled program I attached. The labels are a little more understandable to me, at least. For example, instead of reg_005, 0, it uses porta, ra0. Porta and RA0 are easily found in the datasheet.

John

The disassembler I used is PICDIS by William Couture ver. 2003. He comments to write "picemulator@yahoo.com" with any questions. Sorry, I did not save the actual link that I used to download it. The disassembled program opens easily complete with colors in MPLab.
 
Last edited:
Top