Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
tama182 said:hey nigel i just noticed, howcome the main board in your tutorial hasn't got anything to clock the pic, theres not crystal or anything
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
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
count
endc
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 TRISB
bcf STATUS, RP0 ;select bank 0
clrf PORTB
start clrf count
read movfw count
goto _7SegDisp
movwf PORTB
goto 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
_7SegDisp addwf PCL ; skips a certain number of instructions
retlw b'11111110' ; code for 0
retlw b'01100000' ; code for 1
retlw b'11011010' ; code for 2
retlw b'11110010' ; code for 3
retlw b'01100110' ; code for 4
retlw b'10110110' ; code for 5
retlw b'10111110' ; code for 6
retlw b'11100000' ; code for 7
retlw b'11111110' ; code for 8
retlw b'11110110' ; code for 9
retlw b'11101110' ; code for A
retlw b'00111110' ; code for b
retlw b'10011100' ; code for C
retlw b'01111010' ; code for d
retlw b'10011110' ; code for E
retlw b'10001110' ; code for F
delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
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
tama182 said:oh, so you cant return from a goto instruction, it only remembers its place from a call instruction, is that right,
but if i use a call to go somwhere, and then in that place i use a further goto, to go somwhere else, and then from that place i use the return instruction will i go backl to where i started from, only the next instruction after call?
tama182 said:oh, so you cant return from a goto instruction, it only remembers its place from a call instruction, is that right,
but if i use a call to go somwhere, and then in that place i use a further goto, to go somwhere else, and then from that place i use the return instruction will i go backl to where i started from, only the next instruction after call?
call Sub1
more code
Sub1 call sub2
return
Sub2 return
Pommie said:And, during all this interrupts come along and they have to remember where to return to as well.
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
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
count ;MAIN 14 COUNT
endc
LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB ;set constant for TRIS register
SWPORT Equ PORTA
SWTRIS Equ TRISA
SW1 Equ 4 ;set constants for the switches
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 ;make sure all LED's are off
BSF SWPORT, LED1
start1 CLRF count
MOVFW count
Start movfw count
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
incf count, w
xorlw d'14' ;check for last (14th) entry
btfsc STATUS, Z
goto start1 ;if start from beginning
incf count, f
CALL DELAY
GOTO Start
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'
Switch1 BTFSC SWPORT, LED1
GOTO JUMP1
BTFSC SWPORT, LED2
GOTO JUMP2
BTFSC SWPORT, LED3
GOTO JUMP3
BTFSC SWPORT, LED4
GOTO JUMP4
retlw 0x00
JUMP1 BCF SWPORT, LED1
BSF SWPORT, LED2
BCF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
JUMP2 BCF SWPORT, LED1
BCF SWPORT, LED2
BSF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
JUMP3 BCF SWPORT, LED1
BCF SWPORT, LED2
BCF SWPORT, LED3
BSF SWPORT, LED4
GOTO BACK
JUMP4 BSF SWPORT, LED1
BCF SWPORT, LED2
BCF SWPORT, LED3
BCF SWPORT, LED4
GOTO BACK
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
ChkKeys btfss SWPORT, SW1
call Switch1
BACK
retlw 0x00
end
tama182 said:hey nigel, what do you think of this, i messed round with on of you circuits so that it only takes on switch to change the tables
tama182 said:How come that all the circuits and icd2 manual have a pull up resister for MCLR, i know that its logic 0 activated, but i thought that the pins on IC's go high if there not connected,
so why is a pull up needed?
also you cant use pull ups on PGC/PGD, again doesn't the same apply here,
so does this mean that you basicly cant use R6 and R7 as logic 0 activated switches, because you couldn't have them usually pulled up when not pressed,
but you could have them as logic 1 activated switches, where they would usually be pulled down, when not pressed.
You should pull them high or low, with resistors, to ensure the default state, then switch to the other state
tama182 said:You should pull them high or low, with resistors, to ensure the default state, then switch to the other state
Well im just following the ICD2 manual, but when it says that you can't use pull ups on the pgc and pgd inputs, this is just for the programming right?
so if i was to have pull ups on on RB6 and RB7, i could put them on after the programming, is that right?