In the summer I plan to get setup and do some beginner programming, I hope it's not going to be this difficult
I explained how the program works only 6 times. One reading the thread carefully would have a better understanding. That said below is a simplified flowchart for any suggestions:
Simplified Flowchart:
1- Set Values for Color1, Color2, Color3 (variables used by the main program to set colors).
2- Main Program is called. Main sets the bits for PORTB, and places variables above in PORTA one at a time, and does puedo-pwm (modulates). PortB sets the anodes, while PORTA sets R,G,B (Cathodes) in the hardware.
3- Main calls an OUTPUT routine where Bytes in PORTA, and PORTB are pushed out. This completes one entire cycle.
4- Set new values for Color1, Color2, Color3
5- Call Main Program
6- Main calls the Output routine
7- Repeat this process for new values of Color1, Color2, Color3 (25 times)
I am currently reading up examples of table lookups and storing values in EEPROM. I will give it a good try to see if PIC treats those values placed in variables any differently.
;Tutorial 2.3 - Nigel Goodwin 2002
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count ;used in table read routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register
SWPORT Equ PORTA
SWTRIS Equ TRISA
SW1 Equ 7 ;set constants for the switches
SW2 Equ 6
SW3 Equ 5
SW4 Equ 4
LED1 Equ 3 ;and for the LED's
LED2 Equ 2
LED3 Equ 1
LED4 Equ 0
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
movlw b'11110000' ;set PortA 4 inputs, 4 outputs
movwf SWTRIS
bcf STATUS, RP0 ;select bank 0
clrf LEDPORT ;set all outputs low
clrf SWPORT
bsf SWPORT, LED1 ;set initial pattern
Start clrf count ;set counter register to zero
Read movf count, w ;put counter value in W
btfsc SWPORT, LED1 ;check which LED is lit
call Table1 ;and read the associated table
btfsc SWPORT, LED2
call Table2
btfsc SWPORT, LED3
call Table3
btfsc SWPORT, LED4
call Table4
movwf LEDPORT
call Delay
incf count, w
xorlw d'14' ;check for last (14th) entry
btfsc STATUS, Z
goto Start ;if start from beginning
incf count, f ;else do next
goto Read
Table1 ADDWF PCL, f ;data table for bit pattern
retlw b'10000000'
retlw b'01000000'
retlw b'00100000'
retlw b'00010000'
retlw b'00001000'
retlw b'00000100'
retlw b'00000010'
retlw b'00000001'
retlw b'00000010'
retlw b'00000100'
retlw b'00001000'
retlw b'00010000'
retlw b'00100000'
retlw b'01000000'
Table2 ADDWF PCL, f ;data table for bit pattern
retlw b'11000000'
retlw b'01100000'
retlw b'00110000'
retlw b'00011000'
retlw b'00001100'
retlw b'00000110'
retlw b'00000011'
retlw b'00000011'
retlw b'00000110'
retlw b'00001100'
retlw b'00011000'
retlw b'00110000'
retlw b'01100000'
retlw b'11000000'
Table3 ADDWF PCL, f ;data table for bit pattern
retlw b'01111111'
retlw b'10111111'
retlw b'11011111'
retlw b'11101111'
retlw b'11110111'
retlw b'11111011'
retlw b'11111101'
retlw b'11111110'
retlw b'11111101'
retlw b'11111011'
retlw b'11110111'
retlw b'11101111'
retlw b'11011111'
retlw b'10111111'
Table4 ADDWF PCL, f ;data table for bit pattern
retlw b'00111111'
retlw b'10011111'
retlw b'11001111'
retlw b'11100111'
retlw b'11110011'
retlw b'11111001'
retlw b'11111100'
retlw b'11111100'
retlw b'11111001'
retlw b'11110011'
retlw b'11100111'
retlw b'11001111'
retlw b'10011111'
retlw b'00111111'
ChkKeys btfss SWPORT, SW1
call Switch1
btfss SWPORT, SW2
call Switch2
btfss SWPORT, SW3
call Switch3
btfss SWPORT, SW4
call Switch4
retlw 0x00
Switch1 clrf SWPORT ;turn all LED's off
bsf SWPORT, LED1 ;turn LED1 on
retlw 0x00
Switch2 clrf SWPORT ;turn all LED's off
bsf SWPORT, LED2 ;turn LED2 on
retlw 0x00
Switch3 clrf SWPORT ;turn all LED's off
bsf SWPORT, LED3 ;turn LED3 on
retlw 0x00
Switch4 clrf SWPORT ;turn all LED's off
bsf SWPORT, LED4 ;turn LED4 on
retlw 0x00
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 call ChkKeys ;check the keys
movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end
You're over complicating things - check my tutorials which show how simple things are.
You also need to post your entire code, and to do so within code tags (click on go advanced to get that option) in order to keep the formatting correct.
QUOTE]
As for future code posting, duly noted. I was wondering how you guys did that.
As for example code: Good Stuff. I have a few quick questions.
Comment1: If I understand it corectly you have the Table 1 Pattern runing as default.
Comment2: And the SW testing is running in the background. When SW test indicates one of SW's pressed (set to zero), it sends a flag to LED Testing portion that one of the LED's is on hence switching the pattern mode to that specific SW (and associated LED).
Question1: Is that why you did not call "Chkeys" in the main body (LED test portion) as it was not necessary since it is running in the background?
Question2: In SW testing portion (Chkeys) at the end of each test it returns w=0. Where does it return to? (does it set w=0 and continues running SW-test in the background?)
Question3: Why did you choose to do the SW testing after LED testing? Was it because you wanted the default pattern-Table1 to continue to run without any SW's pressed? Does it matter where the SW-Testing (Chkeys) is done?
Thanks for the info.
Regards,
Rom
Something interesting and new to me that I noticed you have done Nigel and that is to use RA5 as an input to set an event (SW). I thought RA5's function was limited to MCLR (Clearing all outputs). So if you set all bits in TRISA low except RA5 (TRIS5), all pins will be outputs except RA5 which will act as an input only bypassing the function of master clear, and enables you to read the status of it and do something with it?
And if you set it low, it will act as MCLR?
As for future code posting, duly noted. I was wondering how you guys did that.
As for example code: Good Stuff. I have a few quick questions.
Comment1: If I understand it corectly you have the Table 1 Pattern runing as default.
Comment2: And the SW testing is running in the background. When SW test indicates one of SW's pressed (set to zero), it sends a flag to LED Testing portion that one of the LED's is on hence switching the pattern mode to that specific SW (and associated LED).
Question1: Is that why you did not call "Chkeys" in the main body (LED test portion) as it was not necessary since it is running in the background?
Question2: In SW testing portion (Chkeys) at the end of each test it returns w=0. Where does it return to? (does it set w=0 and continues running SW-test in the background?)
Question3: Why did you choose to do the SW testing after LED testing? Was it because you wanted the default pattern-Table1 to continue to run without any SW's pressed? Does it matter where the SW-Testing (Chkeys) is done?
Thanks for the info.
You can set the config register to use MCLR as an input pin, and my tutorials all do that so as to give an extra pin, they also set the internal oscillator, and allocate the crystal pins as I/O as well.
These functions depend on the PIC you use, and was one of the reasons for choosing the 16F628 at the time.
I see it now that you pointed it out. I skipped over Delay since I thought it is just a normal delay function. So in the main body of program I could easily call on Chkeys direct in place of your Delay call. Once the status of RA5 changes trigger the main program to read next line of the table lookup. Now it makes perfect sense.Chkeys is run from within the delay routine, I can't even remember why I did it that way now - I suspect it was carried over from a previous version
Assuming that I use RA5 as a SW indicator what is the internal flag for status change of this pin?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?