SPQR: .... Cmq per rcc.roberto che mi ha smerdato praticamente al primo post,ed essendo admin, e quindi verro' bannato, perché sappiamo come vanno certe cose, ecco promesso la foto della mia incapacità'.
Sarebbe gradita un po' meno di arroganza e superbia...e magari un po' più di educazione... questa è la tua presentazione:
Salve
Salve sono SPQR, e di elettronica ci capisco poco e niente mi diletto un po in facili circuiti.. ma niente al vostro livello..
umitcan
postato il: 20.11.2025, alle ore 21:38
codificatore tastiera atari
Il cristallo utilizzato nel circuito è da 20 MHz, ma l'uscita sui pin dati e clock è alla velocità della porta PS/2.
È possibile utilizzare il PIC18F46K22 al posto del PIC16f877, perché i pin sono gli stessi. Allego il file esadecimale.
Grazie.
; PIC16f877a to PIC18f46k22 Assembler Migration by Ümit CAN
; November, 2025
; Microchip Program : MPLAB IDE v8.92
LIST P=18F46K22 ; ; list directive to define processor , F=INHX32
#include <p18f46k22.inc> ; processor specific variable definitions
;errorlevel +302 ;Disable bank switch warning +302=enable
; Assembly source line config statements
; config statements should precede project file includes.
CONFIG CP0 = OFF ; Block 0 (000800-003FFFh) not code-protected.
CONFIG WDTEN = OFF ; Watch dog timer is always disabled. SWDTEN has no effect.
CONFIG BOREN = OFF ; Brown-out Reset disabled in hardware and software.
CONFIG PWRTEN = ON ;Power up timer enabled.
CONFIG FOSC = HSHP ;HS oscillator (high power > 16 MHz).
CONFIG LVP = OFF ;Single-Supply ICSP disabled.
CONFIG CPD = OFF ;Data EEPROM not code-protected.
;Define the port data
#DEFINE KB_DATo PORTA,0
#DEFINE KB_CLKo PORTA,1
#DEFINE KB_DATi PORTA,2
#DEFINE KB_CLKi PORTA,3
#DEFINE stallr_a PORTA,5
#DEFINE scan_enable PORTB,7
#define KB_ERROR 0xFE
cblock 0x20
temp ;misc scratch byte
counter ;used in the SPI routines
; Used by the PS2 keyboard routines
parity
kb_data
host_data
RX_error
KB_init
wait_counter
temp0
; RAM to hold the current and last button states
portA_mirror
portA_last
portB_mirror
portB_last
portC_mirror
portC_last
portD_mirror
portD_last
portE_mirror
portE_last
;Delay variables
d1
d2
d3
endc
;addwf 0x37, w, A
;addwf 0x38, w, A
;addwf 0x38, F, A
;addwf 0x39, F
;bsf PORTC,1
;addwf 0x39, F
;addwf 0x37, w, A
;org 0x0000
;org 0x0000 ; program starting address after power on reset
;bra init
org 0x00 ; processor reset vector
bra init ; go to beginning of program
; org 0x08
;retfie
;movlb D'1' ; select Bank1 and Access Ram
;bra ISR
org 0x08
bra HIGH_ISR
org 0x18
bra LOW_ISR
LOW_ISR
retfie
HIGH_ISR
;bcf INTCON, GIE ; disable interrupts
;bcf INTCON, INT0IF ; External Interrupt Flag bit bcf INTCON, INTF
;bsf INTCON, GIE ; enable interrupts
retfie
;----------------------------------------------------------
Receive_device:
clrf kb_data
btfss KB_CLKi ;Test for Request-to-send
retlw 0xFE
btfsc KB_DATi
retlw 0xFE
movlw 0x08 ;Count 8 rising edges
movwf counter
movlw 0xFF
clrf wait_counter
Start_bit:
decfsz wait_counter, f
bra here0
retlw 0xFE
here0:
btfsc KB_CLKi ;Wait for clock to go low
bra Start_bit
btfsc KB_DATi ;Is start bit low
retlw 0xFE ;If not exit with error
movlw 0xFF
clrf wait_counter
Wait_Start_bit:
decfsz wait_counter, f
bra here1
retlw 0xFE
here1:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_Start_bit
RX_data:
decfsz wait_counter, f
bra here2
retlw 0xFE
here2:
btfsc KB_CLKi ;Wait for clock to go low
bra RX_data ;Data is valid when clock is low
bcf STATUS, C
btfsc KB_DATi
bsf STATUS, C
rrcf kb_data,f ;rrf and rlf are PIC16 instructions. PIC18 has the option of using the carry or not; try rrcf and rlcf.
movlw 0xFF
clrf wait_counter
Wait_RX_data:
decfsz wait_counter, f
bra here3
retlw 0xFE
here3:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_RX_data
movlw 0xFF
clrf wait_counter
decfsz counter, f
bra RX_data
movlw 0xFF
clrf wait_counter
Parity_bit:
decfsz wait_counter, f
bra here4
retlw 0xFE
here4:
btfsc KB_CLKi ;Wait for clock to go low
bra Parity_bit
clrf parity ;Check and record parity
btfsc KB_DATi
incf parity, f
movlw 0xFF
clrf wait_counter
Wait_Parity_bit:
decfsz wait_counter, f
bra here5
retlw 0xFE
here5:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_Parity_bit
movlw 0xFF
clrf wait_counter
Stop_bit:
decfsz wait_counter, f
bra here6
retlw 0xFE
here6:
btfsc KB_CLKi ;Wait for clock to go low
bra Stop_bit
movlw 0xFF
clrf wait_counter
Wait_Stop_bit:
decfsz wait_counter, f
bra here7
retlw 0xFE
here7:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_Stop_bit
return
;----------------------------------------------------------
Send_device:
movwf temp0
btfss KB_CLKi ;Test for Request-to-send
retlw 0xFE
btfss KB_DATi
retlw 0xFE
movlw 0x08 ;Count 8 rising edges
movwf counter
;bsf STATUS, RP0 ;pull clock low 1bff BSF f,b Bit set f 1 › f(b) (select bank 1)
;MOVLB 0x0 ; Set BSR for banked SFRs
;****************************************
;RP0=1 iken Bank1
;RP0=0 iken Bank0
;****************************************
;bcf KB_CLKi ;KB_CLKi PORTA,3 8bff BCF f,b Bit clear f 0 › f(b)
call KB_CLKi_0
;MOVLB 0x0 ; Set BSR for banked SFRs ; bcf STATUS, RP0
call delay_20us ;100us delay
call delay_20us
call delay_20us
call delay_20us
call delay_20us
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0 ;pull data low and release clock
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
RX_data0:
btfsc KB_CLKi ;Wait for clock to go low
bra RX_data0
;Data is valid when clock is high
movf temp0, w
xorwf parity, f
;MOVLB 0x0 ; Set BSR for banked SFRs ;bsf STATUS, RP0
andlw 0x01
btfss STATUS, Z
;bsf KB_DATi
call KB_DATi_1
btfsc STATUS, Z
;bcf KB_DATi
call KB_DATi_0
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
rrcf temp0, f ;rrf and rlf are PIC16 instructions. PIC18 has the option of using the carry or not; try rrcf and rlcf.
RX_data1:
btfss KB_CLKi ;Wait for clock to go high
bra RX_data1
decfsz counter, f
bra RX_data0
Parity_bit0:
btfsc KB_CLKi ;Wait for clock to go low
bra Parity_bit0
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0 ;Set parity
btfss parity, 0
;bsf KB_DATi
call KB_DATi_1
btfsc parity, 0
;bcf KB_DATi
call KB_DATi_0
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
Wait_Parity_bit0:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_Parity_bit0
Stop_bit0:
btfsc KB_CLKi ;Wait for clock to go low
bra Stop_bit0
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0 ;Set stop and release data line
;bsf KB_DATi
call KB_DATi_1
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
Wait_Stop_bit0:
btfss KB_CLKi ;Wait for clock to go high
bra Wait_Stop_bit0
Ack_bit0:
btfsc KB_CLKi ;Wait for clock to go low
bra Ack_bit0
btfss KB_DATi
retlw 0xFE
Ack_bit1:
btfss KB_CLKi ;Wait for clock to go high
bra Ack_bit1
retlw 0x00
;----------------------------------------------------------
Send_host:
movwf temp0
InhibitLoop
btfss KB_CLKo ;Test for inhibit
bra InhibitLoop
call delay_20us
call delay_20us
btfss KB_CLKo
bra InhibitLoop
btfss KB_DATo ;Test for inhibit
retlw 0xFE ;alt program? ça??ran ana programana dallamadan önce W saklay?c?s?na de?er yerle?tirir.
clrf parity
movlw 0x08 ; high-priority interrupt service routine
movwf counter
movlw 0x00
call KBBitOut ;Start bit (0)
btfss KB_CLKo ;Test for inhibit
bra Send_host_end
nop
nop
nop
nop
Send_host_data:
movf temp0, w
xorwf parity, f
call KBBitOut ;Data bits
btfss KB_CLKo ;Test for inhibit
bra Send_host_end
rrcf temp0, f ;rrf and rlf are PIC16 instructions. PIC18 has the option of using the carry or not; try rrcf and rlcf.
decfsz counter, f
bra Send_host_data
nop
nop
comf parity, w
call KBBitOut ;Parity bit
btfss KB_CLKo ;Test for inhibit
bra Send_host_end
nop
nop
nop
nop
nop
movlw 0xFF
call KBBitOut ;Stop bit (1)
call delay_20us
retlw 0x00
Send_host_end: ;Release clock and data and abort transmission
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0
;bsf KB_DATo
call KB_DATo_1
;bsf KB_CLKo
call KB_CLKo_1
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
retlw 0xFE ;alt program? ça??ran ana programa dallamadan önce W saklay?c?s?na de?er yerle?tirir.
KBBitOut:
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0
andlw 0x01
btfss STATUS, Z
;----------------------------------------------------------
Receive_host:
clrf host_data
btfss KB_CLKo ;Test for clock low
retlw 0xFE
btfsc KB_DATo ;Test for inhibit
retlw 0xFE
clrf parity
movlw 0x08
movwf counter
call delay_20us
Receive_host_data:
call KBBitIn ;Data bits
btfss KB_CLKo ;Test for inhibit
retlw 0xFE
bcf STATUS, C
rrcf host_data, f ;rrf and rlf are PIC16 instructions. PIC18 has the option of using the carry or not; try rrcf and rlcf.
iorwf host_data, f
xorwf parity,f
decfsz counter, f
bra Receive_host_data
nop
call KBBitIn ;Parity bit
btfss KB_CLKo ;Test for inhibit
retlw 0xFE
xorwf parity, f
nop
nop
nop
nop
nop
ByteInLoop1
nop
call KBBitIn ;Stop bit
btfss KB_CLKo ;Test for inhibit
retlw 0xFE
xorlw 0x00
btfsc STATUS, Z
clrf parity
btfsc STATUS, Z ;Stop bit = 1?
bra ByteInLoop1 ; No--keep clocking.
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0 ;Acknowledge
;bcf KB_DATo
call KB_DATo_0
call delay_20us
;bcf KB_CLKo
call KB_CLKo_0
call delay_20us
call delay_20us
;bsf KB_CLKo
call KB_CLKo_1
call delay_20us
;bsf KB_DATo
call KB_DATo_1
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
;Delay for .5 seconds
Delay_500ms:
movlw 0x16 ;2499999 cycles
movwf d1
movlw 0x74
movwf d2
movlw 0x06
movwf d3
Delay_500
decfsz d1, f
bra $+4 ;***************BRA $+2
decfsz d2, f
bra $+4 ;******************BRA $+2
decfsz d3, f
bra Delay_500
return
delay_1ms:
movlw 0xE7 ;4998 cycles
movwf d1
movlw 0x04
movwf d2
Delay_1:
decfsz d1, f
bra $+4 ;*****************BRA $+2
decfsz d2, f
bra Delay_1
nop
nop
return
delay_50ms:
movlw 0x4F ;249998 cycles
movwf d1
movlw 0xC4
movwf d2
Delay_50
decfsz d1, f
bra $+4 ;********************* BRA $+2
decfsz d2, f
bra Delay_50
bra $+4 ; BRA $+1 *************************************************
return
;**********************************************************
; Initialize all the ports and stuff
init
; b
;MOVank 0LB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0 ;BRA the right page
;Setup default port states
;MOVLB 0xF ; Set BSR for banked SFRs
movlb b'1111' ; Set BSR for banked SFRs
;movlb b'0001' ; Set BSR for banked SFRs
;#DEFINE KB_DATo PORTA,0
movlw b'00000000'
movwf PORTA
movlw b'00000000'
movwf PORTB
movlw b'00000000'
movwf PORTC
movlw b'00000000'
movwf PORTD
movlw b'00000000'
movwf PORTE
movlw b'00000000' ; Configure I/O
MOVWF ANSELA ; Set RA0, RA1, RA2, RA3, RA5 to digital input
; All ANSEL register bits default to 1
MOVWF ANSELB
MOVWF ANSELC
MOVWF ANSELD
MOVWF ANSELE
;********************************************************************
;Disable A2D
;movlw b'00000000' ; Setup A2D on all portA pins and set osc. bits
;k de?erini w registirina yükle.
;000 = Channel 0 (AN0)
;movwf ADCON0 ;
;w registerindeki de?eri ADCON0'a yükle
; bank 1
;MOVLB 0x0 ; Set BSR for banked SFRs bsf STATUS, RP0 ; BRA the right page
;MOVLB 0xF
;MOVWF ANSELA,0 ; for digital inputs
;movlw b'10111100';
movlw b'10000000' ;bit 7 ADFM: A/D result format select bit 0 left 1 riht justified
; bit 5-3 ACQT<2:0> 111 = 20 TAD 000 = 0 TAD
movwf ADCON2
;return
movlw b'00000010' ;bit 1-0 NVCFG 10 = Reserved
movwf ADCON1 ;bit 3-2 PVCFG 00 = A/D VREF + connected to internal signal, AV DD
;bit 6-4 Unimplemented: Read as 0
;bit 7 TRIGSEL 0 = Selects the special trigger from CCP5
MOVLW b'00000000' ;AN0
;MOVLW b'00000000' ; bit 0 ADON: ADC Enable bit 1 = ADC is enabled
MOVWF ADCON0 ; bit 1 GO/DONE: A/D Conversion Status bit 1 = progress. 0 = completed
; CHS<4:0>: Analog Channel Select bits 00000 = AN0
; bit 7 Unimplemented: Read as 0
;****************************************************************************
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0 ;BRA the right page
; keyboard and host
; H K
; AA
; FF FA
; AA
; ED FA
; 00 FA
; FF FA
; AA
; F3 FA
; 00 FA
; ED FA
; 00 FA
; ED FA
; 00 FA
; F3 FA
; 20 FA
; Button Maping
; PA4 => a => P2_RIGHT => KEYCODE_G
; PA5 => b => P2_DOWN => KEYCODE_F
; PB0 => c => P1_BUTTON5 => KEYCODE_Z
; PB1 => d => P1_COIN => KEYCODE_5
; PB2 => e => P1_START => KEYCODE_1
; PB3 => f => P1_DOWN => KEYCODE_DOWN
; PB4 => g => P1_RIGHT => KEYCODE_RIGHT
; PB5 => h => P1_UP => KEYCODE_UP
; PB6 => i => P1_LEFT => KEYCODE_LEFT
; PC0 => k => P2_BUTTON2 => KEYCODE_S
; PC1 => l => P2_BUTTON3 => KEYCODE_D
; PC2 => m => P2_BUTTON4 => KEYCODE_W
; PC3 => n => P2_START => KEYCODE_2
; PC4 => o => P2_BUTTON6 => KEYCODE_Y
; PC5 => ESC
; PC6 => q => P1_BUTTON4 => KEYCODE_LSHIFT
; PC7 => r => P1_BUTTON3 => KEYCODE_SPACE
; PD0 => s => P2_COIN => KEYCODE_6
; PD1 => t => P2_BUTTON5 => KEYCODE_T
; PD2 => u =>
; PD3 => v => P2_BUTTON7 => KEYCODE_A
; PD4 => w => P1_BUTTON2 => KEYCODE_LALT
; PD5 => x => P1_BUTTON1 => KEYCODE_LCONTROL
; PD6 => y => P1_BUTTON7 => KEYCODE_LCONTROL
; PD7 => z => P1_BUTTON6 => KEYCODE_X
; PE0 => 0 => P2_LEFT => KEYCODE_D
; PE1 => 1 => P2_UP => KEYCODE_R
; PE2 => 2 => P2_BUTTON1 => KEYCODE_A
;--------------------------------------------------------------------
;Start of the main program, aka were it all goes down.
;--------------------------------------------------------------------
clrf KB_init
main:
btfss scan_enable
bra Skip_delay
call delay_1ms
call delay_1ms
call delay_1ms
call delay_1ms
call delay_1ms
Skip_delay:
;Check to see if keyboard wants to talk
btfsc scan_enable
bra PC_to_device
call Receive_device
sublw KB_ERROR
;bz PC_to_device
bnz tmp0
bra PC_to_device
tmp0:
;return
;Forward data to PC
movf kb_data, w
call Send_host
movf KB_init, w
sublw 0x00
;bz state0
bnz tmp1
bra state0
tmp1:
;return
movf KB_init, w
sublw 0x01
;bz state1
bnz tmp2
bra state1
tmp2:
;return
bra PC_to_device
state0:
;First reset the keybord
call delay_1ms
movlw 0xFF
call Send_device
incf KB_init, f
bra PC_to_device
state1:
;Second send the ED command
movlw 0xED
call Send_device
wait_for_ack1:
btfss KB_CLKi
bra wait_for_ack1
btfsc KB_DATi
bra wait_for_ack1
call Receive_device
movlw 0x00
call Send_device
incf KB_init, f
bra PC_to_device
PC_to_device:
call Receive_host
movwf RX_error
sublw 0x00
;bnz show_error
bnz tmp3
;bra show_error
tmp3:
bra show_error
;return
call delay_1ms
movlw 0xFA
call Send_host
movf host_data, w
sublw 0xFF
;bnz main
bnz tmp4
;bra main
tmp4:
bra main
;return
rcall Delay_500ms
movlw 0xAA
rcall Send_host
bra main
show_error:
movf RX_error, w
sublw 0xFE
;bz check_inputs
bnz tmp5
bra check_inputs
tmp5:
;return
rcall delay_50ms
movf RX_error, w
bra main
check_inputs:
btfss scan_enable
bra main
;Scan the keys for presses and releases
;Check the buttons that are on PORTA<--------------------
CheckA:
movf PORTA, w
andlw 0x30;
movwf portA_mirror
xorwf portA_last, w
;bz CheckB
bnz tmp6
bra CheckB
tmp6:
;return
checkA4_pressed:
btfsc portA_mirror, 4
bra checkA4_released
btfss portA_last, 4
bra checkA4_released
movlw 0x34 ;Do pressed message
call Send_host
checkA4_released:
btfss portA_mirror, 4
bra checkA5_pressed
btfsc portA_last, 4
bra checkA5_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x34
call Send_host
checkA5_pressed:
btfsc portA_mirror, 5
bra checkA5_released
btfss portA_last, 5
bra checkA5_released
movlw 0x2B ;Do pressed message
call Send_host
checkA5_released:
btfss portA_mirror, 5
bra end_checkA
btfsc portA_last, 5
bra end_checkA
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x2B
call Send_host
end_checkA:
movf portA_mirror, w
movwf portA_last
;Check the buttons that are on PORTB<--------------------
CheckB:
movf PORTB, w
movwf portB_mirror
xorwf portB_last, w
;bz CheckC
bnz tmp7
bra CheckC
tmp7:
;return
checkB0_pressed:
btfsc portB_mirror, 0
bra checkB0_released
btfss portB_last, 0
bra checkB0_released
movlw 0x1A ;Do pressed message
call Send_host
checkB0_released:
btfss portB_mirror, 0
bra checkB1_pressed
btfsc portB_last, 0
bra checkB1_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1A
call Send_host
checkB1_pressed:
btfsc portB_mirror, 1
bra checkB1_released
btfss portB_last, 1
bra checkB1_released
movlw 0x2E ;Do pressed message
call Send_host
checkB1_released:
btfss portB_mirror, 1
bra checkB2_pressed
btfsc portB_last, 1
bra checkB2_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x2E
call Send_host
checkB2_pressed:
btfsc portB_mirror, 2
bra checkB2_released
btfss portB_last, 2
bra checkB2_released
movlw 0x16 ;Do pressed message
call Send_host
checkB2_released:
btfss portB_mirror, 2
bra checkB3_pressed
btfsc portB_last, 2
bra checkB3_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x16
call Send_host
checkB3_pressed:
btfsc portB_mirror, 3
bra checkB3_released
btfss portB_last, 3
bra checkB3_released
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x72
call Send_host
checkB3_released:
btfss portB_mirror, 3
bra checkB4_pressed
btfsc portB_last, 3
bra checkB4_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x72
call Send_host
checkB4_pressed:
btfsc portB_mirror, 4
bra checkB4_released
btfss portB_last, 4
bra checkB4_released
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x74
call Send_host
checkB4_released:
btfss portB_mirror, 4
bra checkB5_pressed
btfsc portB_last, 4
bra checkB5_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x74
call Send_host
checkB5_pressed:
btfsc portB_mirror, 5
bra checkB5_released
btfss portB_last, 5
bra checkB5_released
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x75
call Send_host
checkB5_released:
btfss portB_mirror, 5
bra checkB6_pressed
btfsc portB_last, 5
bra checkB6_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x75
call Send_host
checkB6_pressed:
btfsc portB_mirror, 6
bra checkB6_released
btfss portB_last, 6
bra checkB6_released
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x6B
call Send_host
checkB6_released:
btfss portB_mirror, 6
bra end_checkB
btfsc portB_last, 6
bra end_checkB
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0xE0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x6B
call Send_host
end_checkB:
movf portB_mirror, w
movwf portB_last
;Check the buttons that are on PORTC<--------------------
CheckC:
movf PORTC, w
movwf portC_mirror
xorwf portC_last, w
;bz CheckD
bnz tmp8
bra CheckD
tmp8:
;return
checkC0_pressed:
btfsc portC_mirror, 0
bra checkC0_released
btfss portC_last, 0
bra checkC0_released
movlw 0x1B ;Do pressed message
call Send_host
checkC0_released:
btfss portC_mirror, 0
bra checkC1_pressed
btfsc portC_last, 0
bra checkC1_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1B
call Send_host
checkC1_pressed:
btfsc portC_mirror, 1
bra checkC1_released
btfss portC_last, 1
bra checkC1_released
movlw 0x23 ;Do pressed message
call Send_host
checkC1_released:
btfss portC_mirror, 1
bra checkC2_pressed
btfsc portC_last, 1
bra checkC2_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x23
call Send_host
checkC2_pressed:
btfsc portC_mirror, 2
bra checkC2_released
btfss portC_last, 2
bra checkC2_released
movlw 0x1D ;Do pressed message
call Send_host
checkC2_released:
btfss portC_mirror, 2
bra checkC3_pressed
btfsc portC_last, 2
bra checkC3_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1D
call Send_host
checkC3_pressed:
btfsc portC_mirror, 3
bra checkC3_released
btfss portC_last, 3
bra checkC3_released
movlw 0x1E ;Do pressed message
call Send_host
checkC3_released:
btfss portC_mirror, 3
bra checkC4_pressed
btfsc portC_last, 3
bra checkC4_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1E
call Send_host
checkC4_pressed:
btfsc portC_mirror, 4
bra checkC4_released
btfss portC_last, 4
bra checkC4_released
movlw 0x35 ;Do pressed message
call Send_host
checkC4_released:
btfss portC_mirror, 4
bra checkC5_pressed
btfsc portC_last, 4
bra checkC5_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x35
call Send_host
checkC5_pressed:
btfsc portC_mirror, 5
bra checkC5_released
btfss portC_last, 5
bra checkC5_released
movlw 0x76 ;Do pressed message
call Send_host
checkC5_released:
btfss portC_mirror, 5
bra checkC6_pressed
btfsc portC_last, 5
bra checkC6_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x76
call Send_host
checkC6_pressed:
btfsc portC_mirror, 6
bra checkC6_released
btfss portC_last, 6
bra checkC6_released
movlw 0x12 ;Do pressed message
call Send_host
checkC6_released:
btfss portC_mirror, 6
bra checkC7_pressed
btfsc portC_last, 6
bra checkC7_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x12
call Send_host
checkC7_pressed:
btfsc portC_mirror, 7
bra checkC7_released
btfss portC_last, 7
bra checkC7_released
movlw 0x29 ;Do pressed message
call Send_host
checkC7_released:
btfss portC_mirror, 7
bra end_checkC
btfsc portC_last, 7
bra end_checkC
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x29
call Send_host
end_checkC:
movf portC_mirror, w
movwf portC_last
;Check the buttons that are on PORTD<--------------------
CheckD:
movf PORTD, w
movwf portD_mirror
xorwf portD_last, w
;bz CheckE
bnz tmp9
bra CheckE
tmp9:
;return
checkD0_pressed:
btfsc portD_mirror, 0
bra checkD0_released
btfss portD_last, 0
bra checkD0_released
movlw 0x36 ;Do pressed message
call Send_host
checkD0_released:
btfss portD_mirror, 0
bra checkD1_pressed
btfsc portD_last, 0
bra checkD1_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x36
call Send_host
checkD1_pressed:
btfsc portD_mirror, 1
bra checkD1_released
btfss portD_last, 1
bra checkD1_released
movlw 0x2C ;Do pressed message
call Send_host
checkD1_released:
btfss portD_mirror, 1
bra checkD2_pressed
btfsc portD_last, 1
bra checkD2_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x2C
call Send_host
checkD2_pressed:
btfsc portD_mirror, 2
bra checkD2_released
btfss portD_last, 2
bra checkD2_released
movlw 0x3C ;Do pressed message
call Send_host
checkD2_released:
btfss portD_mirror, 2
bra checkD3_pressed
btfsc portD_last, 2
bra checkD3_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x3C
call Send_host
checkD3_pressed:
btfsc portD_mirror, 3
bra checkD3_released
btfss portD_last, 3
bra checkD3_released
movlw 0x1C ;Do pressed message
call Send_host
checkD3_released:
btfss portD_mirror, 3
bra checkD4_pressed
btfsc portD_last, 3
bra checkD4_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1C
call Send_host
checkD4_pressed:
btfsc portD_mirror, 4
bra checkD4_released
btfss portD_last, 4
bra checkD4_released
movlw 0x11 ;Do pressed message
call Send_host
checkD4_released:
btfss portD_mirror, 4
bra checkD5_pressed
btfsc portD_last, 4
bra checkD5_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x11
call Send_host
checkD5_pressed:
btfsc portD_mirror, 5
bra checkD5_released
btfss portD_last, 5
bra checkD5_released
movlw 0x14 ;Do pressed message
call Send_host
checkD5_released:
btfss portD_mirror, 5
bra checkD6_pressed
btfsc portD_last, 5
bra checkD6_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x14
call Send_host
checkD6_pressed:
btfsc portD_mirror, 6
bra checkD6_released
btfss portD_last, 6
bra checkD6_released
movlw 0x14 ;Do pressed message
call Send_host
checkD6_released:
btfss portD_mirror, 6
bra checkD7_pressed
btfsc portD_last, 6
bra checkD7_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x14
call Send_host
checkD7_pressed:
btfsc portD_mirror, 7
bra checkD7_released
btfss portD_last, 7
bra checkD7_released
movlw 0x22 ;Do pressed message
call Send_host
checkD7_released:
btfss portD_mirror, 7
bra end_checkD
btfsc portD_last, 7
bra end_checkD
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x22
call Send_host
end_checkD:
movf portD_mirror, w
movwf portD_last
;Check the buttons that are on PORTE<--------------------
CheckE:
movf PORTE, w
movwf portE_mirror
xorwf portE_last, w
;bz End_check
bnz tmp10
bra End_check
tmp10:
;return
checkE0_pressed:
btfsc portE_mirror, 0
bra checkE0_released
btfss portE_last, 0
bra checkE0_released
movlw 0x23 ;Do pressed message
call Send_host
checkE0_released:
btfss portE_mirror, 0
bra checkE1_pressed
btfsc portE_last, 0
bra checkE1_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x23
call Send_host
checkE1_pressed:
btfsc portE_mirror, 1
bra checkE1_released
btfss portE_last, 1
bra checkE1_released
movlw 0x2D ;Do pressed message
call Send_host
checkE1_released:
btfss portE_mirror, 1
bra checkE2_pressed
btfsc portE_last, 1
bra checkE2_pressed
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x2D
call Send_host
checkE2_pressed:
btfsc portE_mirror, 2
bra checkE2_released
btfss portE_last, 2
bra checkE2_released
movlw 0x1C ;Do pressed message
call Send_host
checkE2_released:
btfss portE_mirror, 2
bra end_checkE
btfsc portE_last, 2
bra end_checkE
movlw 0xF0 ;Do released message
call Send_host
call delay_between_TX
movlw 0x1C
call Send_host
Come utente anonimo puoi leggere il contenuto di questo forum ma per aprire una discussione
o per partecipare ad una discussione esistente devi essere registrato ed accedere al sito