Compare commits

...

4 Commits

Author SHA1 Message Date
47d91da1fa added interrupt examples 2025-03-07 11:29:54 -06:00
f4fdcb11c1 cleaned repo 2025-02-27 08:50:19 -06:00
96bee98513 added clock counter 2025-02-25 10:50:25 -06:00
d4a38ac95f fix on decimal count 2025-02-21 10:59:10 -06:00
24 changed files with 335 additions and 6042 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.lst
*.cod

View File

@ -22,7 +22,7 @@ clean:
rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o) rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o)
program: program:
pk2cmd -M -P${PPROC} -Fout.hex pk2cmd -M -P${PPROC} -Fmain.hex
asm: *.asm asm: *.asm
gpasm -p ${ASMPROC} -o main.hex $^ gpasm -p ${ASMPROC} -o main.hex $^

7
README.md Executable file
View File

@ -0,0 +1,7 @@
# Pic GPASM examples
Pic development on linux
## Dependencies
- gputils
- SDCC (Small Device C Compiler) optional for C development
- pk2cmd for pickit programmers

View File

@ -22,7 +22,7 @@ clean:
rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o) rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o)
program: program:
pk2cmd -M -P${PPROC} -Fout.hex pk2cmd -M -P${PPROC} -Fmain.hex
asm: *.asm asm: *.asm
gpasm -p ${ASMPROC} -o main.hex $^ gpasm -p ${ASMPROC} -o main.hex $^

Binary file not shown.

0
blink/main.hex Normal file → Executable file
View File

File diff suppressed because it is too large Load Diff

View File

@ -4,10 +4,10 @@ LIST P=18F4550, F=INHX32 ; Specify processor and hex format
CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output
CONFIG WDT = OFF ; Watchdog Timer off CONFIG WDT = OFF ; Watchdog Timer off
CONFIG LVP = OFF ; Low-Voltage Programming off CONFIG LVP = OFF ; Low-Voltage Programming off
CONFIG MCLRE = OFF ; MCLR pin disabled, RE3 input enabled CONFIG MCLRE = ON ; MCLR pin disabled, RE3 input enabled
;CONFIG PBADEN = OFF ;CONFIG PBADEN = OFF
ORG 0x00 ; Program starts at address 0
ROTA1 EQU 0x01 ROTA1 EQU 0x01
ROTA2 EQU 0x02 ROTA2 EQU 0x02
ROTA3 EQU 0x04 ROTA3 EQU 0x04
@ -18,13 +18,18 @@ R1 EQU 0x020
R2 EQU 0x021 R2 EQU 0x021
R3 EQU 0x024 R3 EQU 0x024
CUENTA EQU 0x022 CUENTA EQU 0x022
CUENTA2 EQU 0x034
TEMP EQU 0x23 TEMP EQU 0x23
DISP0 EQU 0x30 DISP0 EQU 0x30
DISP1 EQU 0x31 DISP1 EQU 0x31
DISP2 EQU 0x32 DISP2 EQU 0x32
DISP3 EQU 0x33 DISP3 EQU 0x33
ORG 0x0000
goto Start
ORG 0x0008
goto loop
Start: Start:
; Initialize PORTB ; Initialize PORTB
@ -32,119 +37,134 @@ Start:
CLRF LATD ; Clear PORTB outputs CLRF LATD ; Clear PORTB outputs
CLRF LATB CLRF LATB
BCF INTCON2, 7 BCF INTCON2, RBPU
MOVLW 0xff MOVLW 0xff
MOVWF TRISB ; set port b to input MOVWF TRISB ; set port b to input
movlw 0x0f movlw 0x0f
movwf ADCON1 movwf ADCON1
clrf LATA
clrf TRISA
bsf RCON, IPEN ; enable priority modes
bsf INTCON, RBIF ; RB Port change interrupt
bsf INTCON, PEIE ; enable peripheral interrupts
bsf INTCON, GIE ; enable global interrupts
bsf INTCON2, RBIP ; rb to high priority
clrf LATE clrf LATE
clrf TRISE clrf TRISE
clrf CUENTA2
movlw 0x06
movwf PORTE
clrf CUENTA
loop: loop:
;movlw 0x17 movf PORTB, W
;movwf CUENTA bcf INTCON, RBIF
;call Delay clrf CUENTA
;call sevensw call splitDigit
;movwf PORTD call Delay
;goto loop
movf PORTB, W movf PORTB, W
xorlw ROTA1 xorlw ROTA1
btfsc STATUS, Z btfsc STATUS, Z
goto leftright goto hexa ; cuenta 1
xorlw ROTA2^ROTA1 xorlw ROTA2^ROTA1
btfsc STATUS, Z btfsc STATUS, Z
goto right goto decimal ; cuenta 2
xorlw ROTA2^ROTA3 xorlw ROTA2^ROTA3
btfsc STATUS, Z btfsc STATUS, Z
goto left goto des ; cuenta 3 wip
xorlw ROTA3^ROTA4 xorlw ROTA3^ROTA4
btfsc STATUS, Z btfsc STATUS, Z
goto alternate goto hexAsc
xorlw ROTA4^ROTA5 xorlw ROTA4^ROTA5
btfsc STATUS, Z btfsc STATUS, Z
goto centerout goto bcdt
xorlw ROTA5^ROTA6 xorlw ROTA5^ROTA6
btfsc STATUS, Z btfsc STATUS, Z
goto outcenter goto hext
goto loop goto loop
leftright: hexa:
CALL Delay ; Delay
RLCF PORTD, f
BTFSS STATUS,0
GOTO leftright ; Repeat the loop
lright:
CALL Delay ; Delay
RRCF PORTD, F
BTFSS STATUS,0
GOTO lright ; Repeat the loop
return
left:
MOVLW 0x80
MOVWF PORTD
rl: CALL Delay ; Delay
RRCF PORTD, F
BTFSS STATUS,0
GOTO rl ; Repeat the loop
return
right:
infsnz CUENTA, W
return
daw
movwf CUENTA
call splitDigit call splitDigit
call Delay call Delay
CALL Delay incf CUENTA, F
goto right call Delay
goto hexa
alternate: des:
movlw 0xaa clrf CUENTA
movwf PORTD clrf CUENTA2
rl:
call splitDigit
call Delay call Delay
movlw 0x55 incf CUENTA, W
movwf PORTD daw
movwf CUENTA
xorlw 0x60
btfss STATUS, Z
goto rl
clrf CUENTA
incf CUENTA2, W
daw
movwf CUENTA2
xorlw 0x60
btfsc STATUS, Z
return
goto rl
decimal:
call splitDigit
call Delay call Delay
incf CUENTA, W
daw
movwf CUENTA
Call Delay
goto decimal
hexAsc:
movlw 0xff
movwf CUENTA
rl2:
call splitDigit
call Delay
decfsz CUENTA
goto rl2
goto hexAsc
bcdt: ;; count to a thousand
clrf CUENTA
clrf CUENTA2
co:
call splitDigit
call Delay
incf CUENTA, W
daw
movwf CUENTA
btfss STATUS, C
goto co
incf CUENTA2, W
daw
movwf CUENTA2
btfss STATUS, C
goto co
return return
centerout: hext:
movlw 0x18 clrf CUENTA
movwf PORTD clrf CUENTA2
call Delay ht:
movlw 0x24 call splitDigit
movwf PORTD
call Delay
movlw 0x42
movwf PORTD
call Delay
movlw 0x81
movwf PORTD
call Delay
return
outcenter:
movlw 0x81
movwf PORTD
call Delay
movlw 0x42
movwf PORTD
call Delay
movlw 0x24
movwf PORTD
call Delay
movlw 0x18
movwf PORTD
call Delay call Delay
incf CUENTA, W
movwf CUENTA
btfss STATUS, Z
goto ht
clrf CUENTA
incf CUENTA2, W
movwf CUENTA2
btfss STATUS, Z
goto ht
return return
splitDigit: splitDigit:
@ -154,12 +174,20 @@ splitDigit:
swapf CUENTA, W swapf CUENTA, W
andlw 0x0f andlw 0x0f
movwf DISP1 movwf DISP1
movf CUENTA2, W
andlw 0x0f
movwf DISP2
swapf CUENTA2, W
andlw 0x0f
movwf DISP3
return return
disp_delay: disp_delay:
movlw D'250' movlw D'250'
movwf R3 movwf R3
disp_delay_inner: disp_delay_inner:
NOP
NOP
NOP NOP
NOP NOP
decfsz R3, F decfsz R3, F
@ -167,11 +195,15 @@ disp_delay_inner:
return return
sevensw: sevensw:
movlw high(sevensw) movlw high(sevenjmp)
movwf PCLATH movwf PCLATH
movf TEMP, W movf TEMP, W
addwf TEMP, W addwf TEMP, W
addwf PCL, F addlw low(sevenjmp)
btfsc STATUS, 0
incf PCLATH, 1
movwf PCL
sevenjmp:
retlw 3Fh retlw 3Fh
retlw 06h retlw 06h
retlw 5Bh retlw 5Bh
@ -179,15 +211,17 @@ sevensw:
retlw 66h retlw 66h
retlw 6Dh retlw 6Dh
retlw 7Dh retlw 7Dh
retlw 07h retlw 07h ; siete
retlw 7Fh retlw 7Fh ; ocho
retlw 6Fh ; A retlw 6Fh ; nueve
retlw 77h ; B retlw 77h ; A
retlw 7Ch ; C retlw 7Ch ; B
retlw 39h ; D retlw 39h ; C
retlw 5Eh ; E retlw 5Eh ; D
retlw 79h ; E
retlw 71h ; F retlw 71h ; F
; Delay subroutine (approx 500ms) ; Delay subroutine (approx 500ms)
Delay: Delay:
MOVLW D'250' ; Outer loop count MOVLW D'250' ; Outer loop count
@ -198,28 +232,50 @@ Delay_Outer:
Delay_Inner: Delay_Inner:
NOP ; Do nothing (No Operation) NOP ; Do nothing (No Operation)
NOP NOP
NOP
NOP
DECFSZ R2, F ; Decrement inner loop counter DECFSZ R2, F ; Decrement inner loop counter
GOTO Delay_Inner ; Repeat inner loop GOTO Delay_Inner ; Repeat inner loop
;; Multiplex code ;; Multiplex code
clrf PORTD call display
movlw 0x04
movwf PORTE
movff DISP0, TEMP
call sevensw
movwf PORTD
call disp_delay
clrf PORTD
movlw 0x02
movwf PORTE
movff DISP1, TEMP
call sevensw
movwf PORTD
DECFSZ R1, F ; Decrement outer loop counter DECFSZ R1, F ; Decrement outer loop counter
GOTO Delay_Outer ; Repeat outer loop GOTO Delay_Outer ; Repeat outer loop
RETURN ; Return from delay RETURN ; Return from delay
display:
clrf PORTD
movff DISP0, TEMP
call sevensw
movwf PORTD
movlw 0x04
movwf PORTE
call disp_delay
clrf PORTD
movff DISP1, TEMP
call sevensw
movwf PORTD
movlw 0x02
movwf PORTE
call disp_delay
clrf PORTD
movff DISP2, TEMP
call sevensw
movwf PORTD
movlw 0x01
movwf PORTE
call disp_delay
clrf PORTD
clrf PORTE
movff DISP3, TEMP
call sevensw
movwf PORTD
movlw 0x10
movwf PORTA
call disp_delay
clrf PORTA
return
END ; End of program END ; End of program
;todopic y aquihayapuntes ;todopic y aquihayapuntes

Binary file not shown.

59
cuenta/main.hex Normal file → Executable file
View File

@ -1,30 +1,39 @@
:020000040000FA :020000040000FA
:10000000956A8C6A8A6AF19EFF0E936E0F0EC16E1E :0400000006EF00F017
:100010008D6A966A060E846E226A8150010AD8B4EF :0800080018EF00F0956A8C6A04
:1000200028EF00F0030AD8B43EEF00F0060AD8B477 :100010008A6AF19EFF0E936E0F0EC16E896A926A14
:1000300035EF00F00C0AD8B44AEF00F0180AD8B433 :10002000D08EF280F28CF28EF1808D6A966A346AFC
:1000400053EF00F0300AD8B464EF00F00DEF00F089 :100030008150F290226A94EC00F0C3EC00F0815001
:1000500098EC00F08336D8A028EF00F098EC00F080 :10004000010AD8B43AEF00F0030AD8B459EF00F02F
:100060008332D8A02EEF00F01200800E836E98EC41 :10005000060AD8B443EF00F00C0AD8B464EF00F0FD
:1000700000F08332D8A037EF00F0120022481200BF :10006000180AD8B46FEF00F0300AD8B482EF00F06D
:100080000700226E75EC00F098EC00F098EC00F0A0 :1000700018EF00F094EC00F0C3EC00F0222AC3EC7F
:100090003EEF00F0AA0E836E98EC00F0550E836ED2 :1000800000F03AEF00F0226A346A94EC00F0C3EC1E
:1000A00098EC00F01200180E836E98EC00F0240E0D :1000900000F022280700226E600AD8A445EF00F085
:1000B000836E98EC00F0420E836E98EC00F0810E97 :1000A000226A34280700346E600AD8B4120045EF83
:1000C000836E98EC00F01200810E836E98EC00F0C5 :1000B00000F094EC00F0C3EC00F022280700226E60
:1000D000420E836E98EC00F0240E836E98EC00F0D4 :1000C000C3EC00F059EF00F0FF0E226E94EC00F04C
:1000E000180E836E98EC00F0120022500F0B306E49 :1000D000C3EC00F0222E66EF00F064EF00F0226A1D
:1000F00022380F0B316E1200FA0E246E0000000041 :1000E000346A94EC00F0C3EC00F022280700226E82
:10010000242E7EEF00F01200010EFA6E23502324FD :1000F000D8A071EF00F034280700346ED8A071EF5B
:10011000F9263F0C060C5B0C4F0C660C6D0C7D0C2D :1001000000F01200226A346A94EC00F0C3EC00F0B4
:10012000070C7F0C6F0C770C7C0C390C5E0C710C7F :100110002228226ED8A484EF00F0226A3428346E9C
:10013000FA0E206EFA0E216E000000000000000092 :10012000D8A484EF00F0120022500F0B306E22385A
:10014000212E9CEF00F0836A040E846E30C023F0F1 :100130000F0B316E34500F0B326E34380F0B336EA1
:1001500084EC00F0836E7CEC00F0836A020E846E07 :100140001200FA0E246E0000000000000000242EB1
:1001600031C023F084EC00F0836E202E9AEF00F073 :10015000A3EF00F01200010EFA6E23502324660F65
:0201700012007B :10016000D8B0FA2AF96E3F0C060C5B0C4F0C660CEB
:100170006D0C7D0C070C7F0C6F0C770C7C0C390C14
:100180005E0C790C710CFA0E206EFA0E216E0000D6
:100190000000212EC7EF00F0D2EC00F0202EC5EFBA
:1001A00000F01200836A30C023F0ABEC00F0836EE5
:1001B000040E846EA1EC00F0836A31C023F0ABEC36
:1001C00000F0836E020E846EA1EC00F0836A32C0F0
:1001D00023F0ABEC00F0836E010E846EA1EC00F016
:1001E000836A846A33C023F0ABEC00F0836E100E98
:0A01F000806EA1EC00F0806A12009E
:020000040030CA :020000040030CA
:04000000000C1F1EB3 :04000000000C1F1EB3
:02000500038175 :020005008381F5
:060008000FC00FE00F40E5 :060008000FC00FE00F40E5
:00000001FF :00000001FF

File diff suppressed because it is too large Load Diff

32
interrupt/Makefile Executable file
View File

@ -0,0 +1,32 @@
# My pic workflow makefile by Fernando R Jacobo
# Dependencies
# SDCC Small Device C Compiler
# pk2cmd for pickit pic programmers
# C compiler variables
SRC=*.c
CC=sdcc
FAMILY=pic16
PROC=18f4550
# ASM and program variables
PPROC=PIC18F4550
ASMPROC=18F4550
all: $(SRC:.c=.hex)
comp: $(SRC)
$(CC) --use-non-free -m$(FAMILY) -p$(PROC) $^
clean:
rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o)
program:
pk2cmd -M -P${PPROC} -Fmain.hex
asm: *.asm
gpasm -p ${ASMPROC} -o main.hex $^
asmp: asm program
.PHONY: all clean

65
interrupt/main.asm Executable file
View File

@ -0,0 +1,65 @@
LIST P=18F4550
#include <P18F4550.inc>
CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output
CONFIG WDT = OFF ; Watchdog Timer off
CONFIG LVP = OFF ; Low-Voltage Programming off
CONFIG MCLRE = ON ; MCLR pin disabled, RE3 input enabled
ORG 0x00
GOTO INIT
ORG 0x08 ; Interrupt vector for high-priority interrupts
GOTO ISR ; Jump to Interrupt Service Routine
INIT:
; === Configure RB4-RB7 as Input ===
movlw 0xff
movwf TRISB
clrf TRISD
clrf LATD
movlw 0x0f
movwf ADCON1
; === Enable RB Port Change Interrupt ===
BCF INTCON2, RBPU ; Enable PORTB pull-ups
BSF INTCON2, 0 ; Set interrupt on high priority RBIP
BSF INTCON, RBIE ; Enable RB Port Change Interrupt
BSF INTCON, GIE ; Enable Global Interrupts
BSF INTCON, PEIE ; Enable Peripheral Interrupts
;BSF INTCON2, 6
; INT0
BSF INTCON, INT0IE
BSF INTCON2, INTEDG0
BSF INTCON, INT1IE
BSF INTCON2, INTEDG1
MAIN_LOOP:
;MOVFF PORTB, PORTD
GOTO MAIN_LOOP ; Stay in loop, wait for interrupts
; === Interrupt Service Routine ===
ISR:
;BTFSS INTCON, RBIF ; Check if RB Change interrupt occurred
;RETFIE ; Return if not triggered
;BTFSS INTCON, INT0IF
;RETFIE
MOVF PORTB, W ; Read PORTB (necessary to clear mismatch condition)
NOP
NOP
NOP
NOP
; === Your Custom Interrupt Handling Code ===
; Example: Toggle PORTD on RB change
;BTG PORTD, 0
MOVFF PORTB, PORTD
BCF INTCON, RBIF ; Clear the RBIF flag
BCF INTCON, INT0IF
BCF INTCON, INT1IF
RETFIE ; Return from interrupt
END

12
interrupt/main.hex Executable file
View File

@ -0,0 +1,12 @@
:020000040000FA
:0400000006EF00F017
:0800080017EF00F0FF0E936EEC
:10001000956A8C6A0F0EC16EF19EF180F286F28EA7
:10002000F28CF288F18CF286F18A15EF00F08150A3
:10003000000000000000000081CF83FFF290F292E8
:04004000F29010002A
:020000040030CA
:04000000000C1F1EB3
:020005008381F5
:060008000FC00FE00F40E5
:00000001FF

Binary file not shown.

0
menu_rota/main.hex Normal file → Executable file
View File

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,17 @@
SRC=*.c # My pic workflow makefile by Fernando R Jacobo
# Dependencies
# SDCC Small Device C Compiler
# pk2cmd for pickit pic programmers
# C compiler variables
SRC=*.c
CC=sdcc CC=sdcc
FAMILY=pic16 FAMILY=pic16
PROC=18f4550 PROC=18f4550
HEX:=main.hex
# ASM and program variables
PPROC=PIC18F4550
ASMPROC=18F4550
all: $(SRC:.c=.hex) all: $(SRC:.c=.hex)
@ -13,10 +21,12 @@ comp: $(SRC)
clean: clean:
rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o) rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o)
asm: *.asm program:
gpasm -p 18F4550 -o main.hex $^ pk2cmd -M -P${PPROC} -Fmain.hex
program: ${HEX} asm: *.asm
pk2cmd -M -PPIC18F4550 -F${HEX} gpasm -p ${ASMPROC} -o main.hex $^
asmp: asm program
.PHONY: all clean .PHONY: all clean

View File

@ -5,7 +5,7 @@ LIST P=18F4550, F=INHX32 ; Specify processor and hex format
CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output
CONFIG WDT = OFF ; Watchdog Timer off CONFIG WDT = OFF ; Watchdog Timer off
CONFIG LVP = OFF ; Low-Voltage Programming off CONFIG LVP = OFF ; Low-Voltage Programming off
;CONFIG MCLRE = OFF ; MCLR pin disabled, RE3 input enabled CONFIG MCLRE = OFF ; MCLR pin disabled, RE3 input enabled
R1 EQU 0x020 R1 EQU 0x020
R2 EQU 0x021 R2 EQU 0x021

Binary file not shown.

2
test/main.hex Normal file → Executable file
View File

@ -3,6 +3,6 @@
:0800100081CF83FF08EF00F02F :0800100081CF83FF08EF00F02F
:020000040030CA :020000040030CA
:04000000000C1F1EB3 :04000000000C1F1EB3
:020005008381F5 :02000500038175
:060008000FC00FE00F40E5 :060008000FC00FE00F40E5
:00000001FF :00000001FF

File diff suppressed because it is too large Load Diff