home | area personale         schemi | tutorial | robotica | pic micro | recensioni         forum | chat irc         faq | contatti         store | Ordina PCB
username
password
cerca

 
FORUM: Pic Micro
Tutto quanto riguarda questi microprocessori... progetti, suggerimenti, aiuti, discussioni...ecc


Encoder ps2 con 16f887
     
Autore Messaggio opzioni
rcc.roberto



[pagine pubblicate]

postato il:
29.12.2014, alle ore 13:38
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.


; Keyboard Encoder
;
; Written by:Steven Easley
; Email: seasley@robotdungeon.com
; Webpage: www.robotdungeon.com
;
;
;

; 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 _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _CPD_OFF


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

;org 0x0004
;org 0x004 ; interrupt vector location
;org 0x008 ; DENEME----------------------------------------------------------------------


;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

;bcf KB_DATi
call KB_DATi_0
;bsf KB_CLKi
call KB_CLKi_1

;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

;bsf KB_DATo
call KB_DATo_1
btfsc STATUS, Z
;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
;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
nop
nop
nop
nop
nop
return

;----------------------------------------------------------
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

;btfss parity, 7 ;Parity correct?
;retlw 0xFF ; No--return error

call delay_20us
retlw 0x00

KBBitIn:
call delay_20us
;MOVLB 0x0 ;Set BSR for banked SFRs bsf STATUS, RP0

;bcf KB_CLKo
call KB_CLKo_0

call delay_20us
call delay_20us

;bsf KB_CLKo
call KB_CLKo_1

;MOVLB 0x0 ; Set BSR for banked SFRs bcf STATUS, RP0
call delay_20us
btfsc KB_DATo
retlw 0x80
retlw 0x00 ;retlw 0x00

;----------------------------------------------------------
;#DEFINE KB_DATo PORTA,0
;#DEFINE KB_CLKo PORTA,1
KB_DATo_1
bcf TRISA,0
bsf KB_DATo
bsf LATA,0
;bsf TRISA,0
return

KB_DATo_0
bcf TRISA,0
bcf KB_DATo
bcf LATA,0
;bsf TRISA,1
return

KB_CLKo_1
bcf TRISA,1
bsf KB_CLKo
bsf LATA,1
;bsf TRISA,1
return

KB_CLKo_0
bcf TRISA,1
bcf KB_CLKo
bcf LATA,1
;bsf TRISA,1
return
;#DEFINE KB_DATi PORTA,2
;#DEFINE KB_CLKi PORTA,3
KB_DATi_1
bcf TRISA,2
bsf KB_DATi
bsf LATA,2
;bsf TRISA,2
return

KB_DATi_0
bcf TRISA,2
bcf KB_DATi
bcf LATA,2
;bsf TRISA,2
return

KB_CLKi_1
bcf TRISA,3
bsf KB_CLKi
bsf LATA,3
;bsf TRISA,3
return

KB_CLKi_0
bcf TRISA,3
bcf KB_CLKi
bcf LATA,3
;bsf TRISA,3
return
;----------------------------------------------------------
;delay for 100 us
delay_between_TX
;call delay_1ms
return

;----------------------------------------------------------
;delay for 20 us
delay_20us
movlw 0x21
movwf d1
Delay_20
decfsz d1, f
bra Delay_20
return
;----------------------------------------------------------
;delay_5us:
;movlw 0x08
;movwf d1
;Delay_5
;decfsz d1, f
;bra Delay_5
;return


;----------------------------------------------------------
;delay for 8000 cycles
;delay_8000
;movlw 0x3E
;movwf d1
;movlw 0x07
;movwf d2
;delay_8000_0
;decfsz d1, f
;bra $+5 ;**********************BRA $+2
;decfsz d2, f
;bra delay_8000_0
;bra $+3 ;BRA $+1***************************
;nop
;return

;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


;movlw b'00000000' ; Configure I/O
;movlw b'11111111' ; Configure I/O
;MOVWF TRISA

;movlw b'11111111' ; Configure I/O
;MOVWF TRISB


;********************************************************************
;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

;bcf INTCON, GIE ; Disable interrupts
call Delay_500ms
movlw 0xAA
call Send_host

; 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

end_checkE:
movf portE_mirror, w
movwf portE_last

End_check:
bra main
end


:020000040000FA
:0200000078D1B5
:0200080009D01D
:0800180000D010001000236A63
:1000200080A6FE0C80B4FE0C080E216EFF0E276A1F
:10003000272E01D0FE0C80B6FBD780B4FE0CFF0E3D
:10004000276A272E01D0FE0C80A6FBD7272E01D0D1
:10005000FE0C80B6FBD7D89080B4D8802332FF0E38
:10006000276A272E01D0FE0C80A6FBD7FF0E276A39
:10007000212EECD7FF0E276A272E01D0FE0C80B66A
:10008000FBD7226A80B4222AFF0E276A272E01D0CE
:10009000FE0C80A6FBD7FF0E276A272E01D0FE0C90
:1000A00080B6FBD7FF0E276A272E01D0FE0C80A654
:1000B000FBD71200286E80A6FE0C80A4FE0C080E52
:1000C000216E4DEC01F052EC01F052EC01F052ECDB
:1000D00001F052EC01F052EC01F045EC01F049EC7A
:1000E00001F080B6FED72850221A010BD8A441ECAB
:1000F00001F0D8B445EC01F0283280A6FED7212EBD
:10010000F0D780B6FED722A041EC01F022B045EC3A
:1001100001F080A6FED780B6FED741EC01F080A6A4
:10012000FED780B6FED780A4FE0C80A6FED7000CBA
:10013000286E80A2FED752EC01F052EC01F080A2B2
:10014000F8D780A0FE0C226A080E216E000ECFECBC
:1001500000F080A21FD00000000000000000285026
:10016000221ACFEC00F080A215D02832212EF7D72A
:1001700000000000221CCFEC00F080A20BD0000099
:100180000000000000000000FF0ECFEC00F052EC79
:1001900001F0000C31EC01F039EC01F0FE0C010B28
:1001A000D8A431EC01F0D8B435EC01F052EC01F0F8
:1001B0003DEC01F052EC01F052EC01F039EC01F0B1
:1001C000000000000000000000001200246A80A26D
:1001D000FE0C80B0FE0C226A080E216E52EC01F07B
:1001E00022EC01F080A2FE0CD89024322412221AB4
:1001F000212EF6D7000022EC01F080A2FE0C221A7C
:1002000000000000000000000000000022EC01F0EF
:1002100080A2FE0C000AD8B4226AD8B4F6D735EC16
:1002200001F052EC01F03DEC01F052EC01F052EC27
:1002300001F039EC01F052EC01F031EC01F052EC3C
:1002400001F0000C52EC01F03DEC01F052EC01F039
:1002500052EC01F039EC01F052EC01F080B0800C6E
:10026000000C9290808089801200929080908990FA
:1002700012009292808289821200929280928992D8
:1002800012009294808489841200929480948994BC
:1002900012009296808689861200929680968996A0
:1002A00012001200210E336E332EFED71200160EEE
:1002B000336E740E346E060E356E332E01D0342E2E
:1002C00001D0352EFAD71200E70E336E040E346ECD
:1002D000332E01D0342EFCD70000000012004F0E48
:1002E000336EC40E346E332E01D0342EFCD701D0C1
:1002F00012000F01000E806E000E816E000E826EE5
:10030000000E836E000E846E000E386F396F3A6FE8
:100310003B6F3C6F800EC06E020EC16E000EC26E4F
:1003200057EC01F0AA0E98EC00F0266A81AE0AD0D4
:1003300064EC01F064EC01F064EC01F064EC01F0B9
:1003400064EC01F081BE26D00FEC00F0FE0801E164
:1003500021D0235098EC00F02650000801E105D090
:100360002650010801E108D015D064EC01F0FF0E21
:100370005AEC00F0262A0ED0ED0E5AEC00F080A6C2
:10038000FED780B4FCD70FEC00F0000E5AEC00F062
:10039000262A00D0E6EC00F0256E000800E10DD022
:1003A00064EC01F0FA0E98EC00F02450FF0800E134
:1003B000BDD77DDFAA0EBCDEB9D72550FE0801E10E
:1003C00003D08DDF2550B2D781AEB0D78050300B2F
:1003D000296E2A1801E128D029B805D02AA803D00F
:1003E000340E98EC00F029A80AD02AB808D0F00EF4
:1003F00098EC00F051EC01F0340E98EC00F029BAC2
:1004000005D02AAA03D02B0E98EC00F029AA0AD016
:100410002ABA08D0F00E98EC00F051EC01F02B0E47
:1004200098EC00F029502A6E81502B6E2C1801E1B7
:10043000AFD02BB005D02CA003D01A0E98EC00F052
:100440002BA00AD02CB008D0F00E98EC00F051ECA4
:1004500001F01A0E98EC00F02BB205D02CA203D0BC
:100460002E0E98EC00F02BA20AD02CB208D0F00E81
:1004700098EC00F051EC01F02E0E98EC00F02BB44B
:1004800005D02CA403D0160E98EC00F02BA40AD0B3
:100490002CB408D0F00E98EC00F051EC01F0160EE0
:1004A00098EC00F02BB60AD02CA608D0E00E98EC01
:1004B00000F051EC01F0720E98EC00F02BA60FD07A
:1004C0002CB60DD0F00E98EC00F051EC01F0E00EDF
:1004D00098EC00F051EC01F0720E98EC00F02BB8A3
:1004E0000AD02CA808D0E00E98EC00F051EC01F0F6
:1004F000740E98EC00F02BA80FD02CB80DD0F00E95
:1005000098EC00F051EC01F0E00E98EC00F051ECAA
:1005100001F0740E98EC00F02BBA0AD02CAA08D087
:10052000E00E98EC00F051EC01F0750E98EC00F044
:100530002BAA0FD02CBA0DD0F00E98EC00F051EC95
:1005400001F0E00E98EC00F051EC01F0750E98EC23
:1005500000F02BBC0AD02CAC08D0E00E98EC00F0D8
:1005600051EC01F06B0E98EC00F02BAC0FD02CBCD2
:100570000DD0F00E98EC00F051EC01F0E00E98EC8C
:1005800000F051EC01F06B0E98EC00F02B502C6E4B
:1005900082502D6E2E1801E19AD02DB005D02EA0DC
:1005A00003D01B0E98EC00F02DA00AD02EB008D07E
:1005B000F00E98EC00F051EC01F01B0E98EC00F0FE
:1005C0002DB205D02EA203D0230E98EC00F02DA260
:1005D0000AD02EB208D0F00E98EC00F051EC01F0E9
:1005E000230E98EC00F02DB405D02EA403D01D0EE0
:1005F00098EC00F02DA40AD02EB408D0F00E98ECA0
:1006000000F051EC01F01D0E98EC00F02DB605D075
:100610002EA603D01E0E98EC00F02DA60AD02EB602
:1006200008D0F00E98EC00F051EC01F01E0E98ECA2
:1006300000F02DB805D02EA803D0350E98EC00F0B0
:100640002DA80AD02EB808D0F00E98EC00F051EC8E
:1006500001F0350E98EC00F02DBA05D02EAA03D08B
:10066000760E98EC00F02DAA0AD02EBA08D0F00E23
:1006700098EC00F051EC01F0760E98EC00F02DBCF7
:1006800005D02EAC03D0120E98EC00F02DAC0AD0A1
:100690002EBC08D0F00E98EC00F051EC01F0120ED8
:1006A00098EC00F02DBE05D02EAE03D0290E98ECAC
:1006B00000F02DAE0AD02EBE08D0F00E98EC00F05F
:1006C00051EC01F0290E98EC00F02D502E6E835065
:1006D0002F6E301801E19AD02FB005D030A003D092
:1006E000360E98EC00F02FA00AD030B008D0F00EF3
:1006F00098EC00F051EC01F0360E98EC00F02FB2BF
:1007000005D030A203D02C0E98EC00F02FA20AD016
:1007100030B208D0F00E98EC00F051EC01F02C0E45
:1007200098EC00F02FB405D030A403D03C0E98EC28
:1007300000F02FA40AD030B408D0F00E98EC00F0EE
:1007400051EC01F03C0E98EC00F02FB605D030A62D
:1007500003D01C0E98EC00F02FA60AD030B608D0BB
:10076000F00E98EC00F051EC01F01C0E98EC00F04B
:100770002FB805D030A803D0110E98EC00F02FA8A8
:100780000AD030B808D0F00E98EC00F051EC01F02F
:10079000110E98EC00F02FBA05D030AA03D0140E39
:1007A00098EC00F02FAA0AD030BA08D0F00E98ECDE
:1007B00000F051EC01F0140E98EC00F02FBC05D0C5
:1007C00030AC03D0140E98EC00F02FAC0AD030BC43
:1007D00008D0F00E98EC00F051EC01F0140E98ECFB
:1007E00000F02FBE05D030AE03D0220E98EC00F002
:1007F0002FAE0AD030BE08D0F00E98EC00F051ECCD
:1008000001F0220E98EC00F02F50306E8450316EC3
:10081000321801E13BD031B005D032A003D0230E15
:1008200098EC00F031A00AD032B008D0F00E98EC6D
:1008300000F051EC01F0230E98EC00F031B205D03D
:1008400032A203D02D0E98EC00F031A20AD032B2C1
:1008500008D0F00E98EC00F051EC01F02D0E98EC61
:1008600000F031B405D032A403D01C0E98EC00F097
:1008700031A40AD032B408D0F00E98EC00F051EC5C
:0E08800001F01C0E98EC00F03150326E4FD596
:020000040030CA
:0300010022183C86
:02000500BF81B9
:060008000FC00FE00F40E5
:00000001FF
segui questo thread con grixFC, per questa funzione devi aver installato il software grixFC

torna su
     

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




 







 
 
indietro | homepage | torna su copyright © 2004/2026 GRIX.IT - La community dell'elettronica Amatoriale