• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Parity ODD

Status
Not open for further replies.

AtomSoft

Well-Known Member
Im using a PIC18F micro and wanted to know how would i go about making a parity ODD bit for a byte. Any help would be great!

I know what it is and stuff just cant wrap my mind on how to check them all? i know i can loop through each bit in the byte and have a count byte and increment it with every 1 but how to i check if its even or odd number?

Im thinking of: Modulus

But how would i use it?
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
Im using a PIC18F micro and wanted to know how would i go about making a parity ODD bit for a byte. Any help would be great!

I know what it is and stuff just cant wrap my mind on how to check them all? i know i can loop through each bit in the byte and have a count byte and increment it with every 1 but how to i check if its even or odd number?
hi atom,
Look at the parity 9th bit option in the USART datasheet.
 

AtomSoft

Well-Known Member
Im acutally not using the UART tho. Im sending out a custom 10Bits of data and i need to send a ODD Parity this is what i got so far. OF COURSE NO GOOD lol

Code:
;ParityTest
	clrf	WREG
	movf	(count2 % 2),W
	movwf	parity

	movlw	0x00
	CPFSGT	parity
	call	SendZero

	CPFSEQ	parity
	call	SendOne
 

AtomSoft

Well-Known Member
heh i found this macro which does the job i just have to reverse my bit testing since this is for EVEN parity:

Code:
CALC_PARITY MACRO ARG_BYTE
        SWAPF   ARG_BYTE, W 
        XORWF   ARG_BYTE, F 
        RRCF    ARG_BYTE, W 
        XORWF   ARG_BYTE, F 
        BTFSC   ARG_BYTE, 2 
        INCF    ARG_BYTE, F 
        ENDM
;..................................................................................
;..................................................................................
;.........................................

;ParityTest
	CALC_PARITY parity
	btfsc	parity,0
	call	SendZero
	btfss	parity,0
	call	SendOne
 
Last edited:

AtomSoft

Well-Known Member
hey all i finally did this lol it was for a AT keyboard. i made the code and here is a list of some of the keys i got so far:
Code:
ESC = 0x3B
F1 = 0x82
F2 = 0x03
F3 = 0x02
F4 = 0x06
F5 = 0x81
F6 = 0x85
F7 = 0xC1
F8 = 0x05
F9 = 0x80
F10 = 0x84
F11 = 0x3C
F12 = 0x83
*PRINT SCREEN = 0x70 0x09
SCROLL LOCK = 0x3F
PAUSE = 0xF0

` = 0x07
1 = 0x0B
2 = 0x0F
3 = 0x13
4 = 0x92
5 = 0x17
6 = 0x1B
7 = 0x9E
8 = 0x1F
9 = 0x23
0 = 0xA2
- = 0x27
= = 0xAA
BACKSPACE = 0x33

TAB = 0x86
q = 0x8A
w = 0x8E
e = 0x12
r = 0x96
t = 0x16
y = 0x9A
u = 0x1E
i = 0xA1
o = 0x22
p = 0xA6   
[ = 0x2A
] = 0xAD
\ = 0xAE

CAPS = 0x2C
a = 0x0E
s = 0x8D
d = 0x91
f = 0x95
g = 0x1A
h = 0x99   
j = 0x9D   
k = 0x21
l = 0xA5
; = 0x26
' = 0x29
ENTER = 0x2D

SHIFTL = 0x09
z = 0x0D
x = 0x11
c = 0x90
v = 0x15
b = 0x19
n = 0x98
m = 0x1D 
, = 0xA0
. = 0xA4
/ = 0x25 
SHIFTR = 0xAC

*CTRL-L = 0x0A
*WIN-L = 0x70 0x8F
*ALT-L = 0x88 
*SPACE = 0x94
*ALT-R = 0x70 0x88
*WIN-R = 0x70 0x93
*PROPERTIES = 0x70 0x97
*CTRL-R = 0x70 0x0A

*INSERT = 0x70 0xBA
*HOME = 0x36
*PAGE UP = 0xBE
*DELETE = 0xB8
*END = 0xB4
*PAGE DOWN = 0x3D

*UP = 0x70 0x85
*LEFT = 0x70 0xB5
*DOWN = 0x70 0x39
*RIGHT = 0x70 0x3A
keys marked with a * are not complete yet or not fully tested as its diner time
 
Last edited:

AtomSoft

Well-Known Member
Anyone got a better idea of converting the Key Code to ASCII besides doing something like: (even tho the below works 100%)

Code:
converttoascii:
	movlw	0xA2
	cpfseq	kbdata
	bra		$+8
	movlw	0x30
	movwf	kbdata
	goto	doneA

	movlw	0x0B
	cpfseq	kbdata
	bra		$+8
	movlw	0x31
	movwf	kbdata
	goto	doneA

	movlw	0x0F
	cpfseq	kbdata
	bra		$+8
	movlw	0x32
	movwf	kbdata
	goto	doneA

	movlw	0x13
	cpfseq	kbdata
	bra		$+8
	movlw	0x33
	movwf	kbdata
	goto	doneA

	movlw	0x92
	cpfseq	kbdata
	bra		$+8
	movlw	0x34
	movwf	kbdata
	goto	doneA

	movlw	0x17
	cpfseq	kbdata
	bra		$+8
	movlw	0x35
	movwf	kbdata
	goto	doneA

	movlw	0x1B
	cpfseq	kbdata
	bra		$+8
	movlw	0x36
	movwf	kbdata
	goto	doneA

	movlw	0x9E
	cpfseq	kbdata
	bra		$+8
	movlw	0x37
	movwf	kbdata
	goto	doneA

	movlw	0x1F
	cpfseq	kbdata
	bra		$+8
	movlw	0x38
	movwf	kbdata
	goto	doneA

	movlw	0x23
	cpfseq	kbdata
	bra		$+8
	movlw	0x39
	movwf	kbdata
	goto	doneA
 

AtomSoft

Well-Known Member
but how would i make the look up? all these keys are random they dont seem to be in a logical order. Unless im not looking good enough heh.
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
The alternative is to have a translation table.

Code:
	dt	0xA2,0x30
	dt	0x0B,0x31
You then search the table for the first entry and return the second. However, this will probably end up bigger than the 256 byte lookup table.

As you're on an 18 series chip each entry above could be a single location.

Mike.
 

AtomSoft

Well-Known Member
Thanks god for VB6 simple
Code:
Private Sub Form_Load()
Dim i As Integer

For i = 0 To 255
    Text1.Text = Text1.Text & vbNewLine & "    retlw   ' '    ;" & Hex(i) 
Next i
End Sub
created this for me:
Code:
    retlw   ' '    ;0
    retlw   ' '    ;1
    retlw   ' '    ;2
    retlw   ' '    ;3
    retlw   ' '    ;4
    retlw   ' '    ;5
    retlw   ' '    ;6
    retlw   ' '    ;7
    retlw   ' '    ;8
    retlw   ' '    ;9
    retlw   ' '    ;A
    retlw   ' '    ;B
    retlw   ' '    ;C
    retlw   ' '    ;D
    retlw   ' '    ;E
    retlw   ' '    ;F
    retlw   ' '    ;10
    retlw   ' '    ;11
    retlw   ' '    ;12
    retlw   ' '    ;13
    retlw   ' '    ;14
    retlw   ' '    ;15
    retlw   ' '    ;16
    retlw   ' '    ;17
    retlw   ' '    ;18
    retlw   ' '    ;19
    retlw   ' '    ;1A
    retlw   ' '    ;1B
    retlw   ' '    ;1C
    retlw   ' '    ;1D
    retlw   ' '    ;1E
    retlw   ' '    ;1F
    retlw   ' '    ;20
    retlw   ' '    ;21
    retlw   ' '    ;22
    retlw   ' '    ;23
    retlw   ' '    ;24
    retlw   ' '    ;25
    retlw   ' '    ;26
    retlw   ' '    ;27
    retlw   ' '    ;28
    retlw   ' '    ;29
    retlw   ' '    ;2A
    retlw   ' '    ;2B
    retlw   ' '    ;2C
    retlw   ' '    ;2D
    retlw   ' '    ;2E
    retlw   ' '    ;2F
    retlw   ' '    ;30
    retlw   ' '    ;31
    retlw   ' '    ;32
    retlw   ' '    ;33
    retlw   ' '    ;34
    retlw   ' '    ;35
    retlw   ' '    ;36
    retlw   ' '    ;37
    retlw   ' '    ;38
    retlw   ' '    ;39
    retlw   ' '    ;3A
    retlw   ' '    ;3B
    retlw   ' '    ;3C
    retlw   ' '    ;3D
    retlw   ' '    ;3E
    retlw   ' '    ;3F
    retlw   ' '    ;40
    retlw   ' '    ;41
    retlw   ' '    ;42
    retlw   ' '    ;43
    retlw   ' '    ;44
    retlw   ' '    ;45
    retlw   ' '    ;46
    retlw   ' '    ;47
    retlw   ' '    ;48
    retlw   ' '    ;49
    retlw   ' '    ;4A
    retlw   ' '    ;4B
    retlw   ' '    ;4C
    retlw   ' '    ;4D
    retlw   ' '    ;4E
    retlw   ' '    ;4F
    retlw   ' '    ;50
    retlw   ' '    ;51
    retlw   ' '    ;52
    retlw   ' '    ;53
    retlw   ' '    ;54
    retlw   ' '    ;55
    retlw   ' '    ;56
    retlw   ' '    ;57
    retlw   ' '    ;58
    retlw   ' '    ;59
    retlw   ' '    ;5A
    retlw   ' '    ;5B
    retlw   ' '    ;5C
    retlw   ' '    ;5D
    retlw   ' '    ;5E
    retlw   ' '    ;5F
    retlw   ' '    ;60
    retlw   ' '    ;61
    retlw   ' '    ;62
    retlw   ' '    ;63
    retlw   ' '    ;64
    retlw   ' '    ;65
    retlw   ' '    ;66
    retlw   ' '    ;67
    retlw   ' '    ;68
    retlw   ' '    ;69
    retlw   ' '    ;6A
    retlw   ' '    ;6B
    retlw   ' '    ;6C
    retlw   ' '    ;6D
    retlw   ' '    ;6E
    retlw   ' '    ;6F
    retlw   ' '    ;70
    retlw   ' '    ;71
    retlw   ' '    ;72
    retlw   ' '    ;73
    retlw   ' '    ;74
    retlw   ' '    ;75
    retlw   ' '    ;76
    retlw   ' '    ;77
    retlw   ' '    ;78
    retlw   ' '    ;79
    retlw   ' '    ;7A
    retlw   ' '    ;7B
    retlw   ' '    ;7C
    retlw   ' '    ;7D
    retlw   ' '    ;7E
    retlw   ' '    ;7F
    retlw   ' '    ;80
    retlw   ' '    ;81
    retlw   ' '    ;82
    retlw   ' '    ;83
    retlw   ' '    ;84
    retlw   ' '    ;85
    retlw   ' '    ;86
    retlw   ' '    ;87
    retlw   ' '    ;88
    retlw   ' '    ;89
    retlw   ' '    ;8A
    retlw   ' '    ;8B
    retlw   ' '    ;8C
    retlw   ' '    ;8D
    retlw   ' '    ;8E
    retlw   ' '    ;8F
    retlw   ' '    ;90
    retlw   ' '    ;91
    retlw   ' '    ;92
    retlw   ' '    ;93
    retlw   ' '    ;94
    retlw   ' '    ;95
    retlw   ' '    ;96
    retlw   ' '    ;97
    retlw   ' '    ;98
    retlw   ' '    ;99
    retlw   ' '    ;9A
    retlw   ' '    ;9B
    retlw   ' '    ;9C
    retlw   ' '    ;9D
    retlw   ' '    ;9E
    retlw   ' '    ;9F
    retlw   ' '    ;A0
    retlw   ' '    ;A1
    retlw   ' '    ;A2
    retlw   ' '    ;A3
    retlw   ' '    ;A4
    retlw   ' '    ;A5
    retlw   ' '    ;A6
    retlw   ' '    ;A7
    retlw   ' '    ;A8
    retlw   ' '    ;A9
    retlw   ' '    ;AA
    retlw   ' '    ;AB
    retlw   ' '    ;AC
    retlw   ' '    ;AD
    retlw   ' '    ;AE
    retlw   ' '    ;AF
    retlw   ' '    ;B0
    retlw   ' '    ;B1
    retlw   ' '    ;B2
    retlw   ' '    ;B3
    retlw   ' '    ;B4
    retlw   ' '    ;B5
    retlw   ' '    ;B6
    retlw   ' '    ;B7
    retlw   ' '    ;B8
    retlw   ' '    ;B9
    retlw   ' '    ;BA
    retlw   ' '    ;BB
    retlw   ' '    ;BC
    retlw   ' '    ;BD
    retlw   ' '    ;BE
    retlw   ' '    ;BF
    retlw   ' '    ;C0
    retlw   ' '    ;C1
    retlw   ' '    ;C2
    retlw   ' '    ;C3
    retlw   ' '    ;C4
    retlw   ' '    ;C5
    retlw   ' '    ;C6
    retlw   ' '    ;C7
    retlw   ' '    ;C8
    retlw   ' '    ;C9
    retlw   ' '    ;CA
    retlw   ' '    ;CB
    retlw   ' '    ;CC
    retlw   ' '    ;CD
    retlw   ' '    ;CE
    retlw   ' '    ;CF
    retlw   ' '    ;D0
    retlw   ' '    ;D1
    retlw   ' '    ;D2
    retlw   ' '    ;D3
    retlw   ' '    ;D4
    retlw   ' '    ;D5
    retlw   ' '    ;D6
    retlw   ' '    ;D7
    retlw   ' '    ;D8
    retlw   ' '    ;D9
    retlw   ' '    ;DA
    retlw   ' '    ;DB
    retlw   ' '    ;DC
    retlw   ' '    ;DD
    retlw   ' '    ;DE
    retlw   ' '    ;DF
    retlw   ' '    ;E0
    retlw   ' '    ;E1
    retlw   ' '    ;E2
    retlw   ' '    ;E3
    retlw   ' '    ;E4
    retlw   ' '    ;E5
    retlw   ' '    ;E6
    retlw   ' '    ;E7
    retlw   ' '    ;E8
    retlw   ' '    ;E9
    retlw   ' '    ;EA
    retlw   ' '    ;EB
    retlw   ' '    ;EC
    retlw   ' '    ;ED
    retlw   ' '    ;EE
    retlw   ' '    ;EF
    retlw   ' '    ;F0
    retlw   ' '    ;F1
    retlw   ' '    ;F2
    retlw   ' '    ;F3
    retlw   ' '    ;F4
    retlw   ' '    ;F5
    retlw   ' '    ;F6
    retlw   ' '    ;F7
    retlw   ' '    ;F8
    retlw   ' '    ;F9
    retlw   ' '    ;FA
    retlw   ' '    ;FB
    retlw   ' '    ;FC
    retlw   ' '    ;FD
    retlw   ' '    ;FE
    retlw   ' '    ;FF
 
Last edited:

AtomSoft

Well-Known Member
Hey guys here is my complete code so far. For some reason its not jumping right. I even tried splitting the table into 4. Not sure if its still to big lol can someone help please... (im having trouble doing the lookup)

Code:
	LIST P=18F2525	;directive to define processor
	#include <P18F2525.INC>	;processor specific variable definitions


    CONFIG	OSC = INTIO67, WDT = OFF, LVP = OFF, XINST = OFF

#define kbt TRISC	
#define kb PORTC
#define kbl LATC
#define kb_dat 1
#define kb_clk 2


		CBLOCK	0x000
		d1
		d2
		d3
		count
		Xmit_Byte
		parity
		kbdata
		pntr
		somedata
		ENDC

CALC_PARITY MACRO ARG_BYTE
        SWAPF   ARG_BYTE, W 
        XORWF   ARG_BYTE, F 
        RRCF    ARG_BYTE, W 
        XORWF   ARG_BYTE, F 
        BTFSC   ARG_BYTE, 2 
        INCF    ARG_BYTE, F 
        ENDM

		ORG	0x0000
		bra Init
		ORG	0x0008
		bra HighInt	

AlphaA	
	addwf	PCL, f
    retlw   ' '    ;0
    retlw   ' '    ;1
    retlw   ' '    ;2
    retlw   ' '    ;3
    retlw   ' '    ;4
    retlw   ' '    ;5
    retlw   ' '    ;6
    retlw   '`'    ;7
    retlw   ' '    ;8
    retlw   ' '    ;9
    retlw   ' '    ;A
    retlw   '1'    ;B
    retlw   ' '    ;C
    retlw   'z'    ;D
    retlw   'a'    ;E
    retlw   '2'    ;F
    retlw   ' '    ;10
    retlw   'x'    ;11
    retlw   'e'    ;12
    retlw   '3'    ;13
    retlw   ' '    ;14
    retlw   'v'    ;15
    retlw   't'    ;16
    retlw   '5'    ;17
    retlw   ' '    ;18
    retlw   'b'    ;19
    retlw   'g'    ;1A
    retlw   '6'    ;1B
    retlw   ' '    ;1C
    retlw   'm'    ;1D
    retlw   'u'    ;1E
    retlw   '8'    ;1F
    retlw   ' '    ;20
    retlw   'k'    ;21
    retlw   'o'    ;22
    retlw   '9'    ;23
    retlw   ' '    ;24
    retlw   0x2F    ;25
    retlw   ';'    ;26
    retlw   '-'    ;27
    retlw   ' '    ;28
    retlw   0x27    ;29
    retlw   '['    ;2A
    retlw   ' '    ;2B
    retlw   ' '    ;2C
    retlw   ' '    ;2D
    retlw   ' '    ;2E
    retlw   ' '    ;2F
    retlw   ' '    ;30
    retlw   ' '    ;31
    retlw   ' '    ;32
    retlw   ' '    ;33
    retlw   ' '    ;34
    retlw   ' '    ;35
    retlw   ' '    ;36
    retlw   ' '    ;37
    retlw   ' '    ;38
    retlw   ' '    ;39
    retlw   ' '    ;3A
    retlw   ' '    ;3B
    retlw   ' '    ;3C
    retlw   ' '    ;3D
    retlw   ' '    ;3E
    retlw   ' '    ;3F
    retlw   ' '    ;40
    retlw   ' '    ;41
    retlw   ' '    ;42
    retlw   ' '    ;43
    retlw   ' '    ;44
    retlw   ' '    ;45
    retlw   ' '    ;46
    retlw   ' '    ;47
    retlw   ' '    ;48
    retlw   ' '    ;49
	retlw	0x00
AlphaB
	addwf	PCL, f
    retlw   ' '    ;4A
    retlw   ' '    ;4B
    retlw   ' '    ;4C
    retlw   ' '    ;4D
    retlw   ' '    ;4E
    retlw   ' '    ;4F
    retlw   ' '    ;50
    retlw   ' '    ;51
    retlw   ' '    ;52
    retlw   ' '    ;53
    retlw   ' '    ;54
    retlw   ' '    ;55
    retlw   ' '    ;56
    retlw   ' '    ;57
    retlw   ' '    ;58
    retlw   ' '    ;59
    retlw   ' '    ;5A
    retlw   ' '    ;5B
    retlw   ' '    ;5C
    retlw   ' '    ;5D
    retlw   ' '    ;5E
    retlw   ' '    ;5F
    retlw   ' '    ;60
    retlw   ' '    ;61
    retlw   ' '    ;62
    retlw   ' '    ;63
    retlw   ' '    ;64
    retlw   ' '    ;65
    retlw   ' '    ;66
    retlw   ' '    ;67
    retlw   ' '    ;68
    retlw   ' '    ;69
    retlw   ' '    ;6A
    retlw   ' '    ;6B
    retlw   ' '    ;6C
    retlw   ' '    ;6D
    retlw   ' '    ;6E
    retlw   ' '    ;6F
    retlw   ' '    ;70
    retlw   ' '    ;71
    retlw   ' '    ;72
    retlw   ' '    ;73
    retlw   ' '    ;74
    retlw   ' '    ;75
    retlw   ' '    ;76
    retlw   ' '    ;77
    retlw   ' '    ;78
    retlw   ' '    ;79
    retlw   ' '    ;7A
    retlw   ' '    ;7B
    retlw   ' '    ;7C
    retlw   ' '    ;7D
    retlw   ' '    ;7E
    retlw   ' '    ;7F
    retlw   ' '    ;80
    retlw   ' '    ;81
    retlw   ' '    ;82
    retlw   ' '    ;83
    retlw   ' '    ;84
    retlw   ' '    ;85
    retlw   ' '    ;86
    retlw   ' '    ;87
    retlw   ' '    ;88
    retlw   ' '    ;89
    retlw   'q'    ;8A
    retlw   ' '    ;8B
    retlw   ' '    ;8C
    retlw   's'    ;8D
    retlw   'w'    ;8E
    retlw   ' '    ;8F
    retlw   'c'    ;90
    retlw   'd'    ;91
    retlw   '4'    ;92
    retlw   ' '    ;93
    retlw   ' '    ;94
    retlw   'f'    ;95
    retlw   'r'    ;96
    retlw   ' '    ;97
    retlw   'n'    ;98
    retlw   'h'    ;99
	retlw	0x00
AlphaC
	addwf	PCL, f
    retlw   'y'    ;9A
    retlw   ' '    ;9B
    retlw   ' '    ;9C
    retlw   'j'    ;9D
    retlw   '7'    ;9E
    retlw   ' '    ;9F
    retlw   ','    ;A0
    retlw   'i'    ;A1
    retlw   '0'    ;A2
    retlw   ' '    ;A3
    retlw   '.'    ;A4
    retlw   'l'    ;A5
    retlw   'p'    ;A6
    retlw   ' '    ;A7
    retlw   ' '    ;A8
    retlw   ' '    ;A9
    retlw   '='    ;AA
    retlw   ' '    ;AB
    retlw   ' '    ;AC
    retlw   ']'    ;AD
    retlw   0x5C   ;AE
    retlw   ' '    ;AF
    retlw   ' '    ;B0
    retlw   ' '    ;B1
    retlw   ' '    ;B2
    retlw   ' '    ;B3
    retlw   ' '    ;B4
    retlw   ' '    ;B5
    retlw   ' '    ;B6
    retlw   ' '    ;B7
    retlw   ' '    ;B8
    retlw   ' '    ;B9
    retlw   ' '    ;BA
    retlw   ' '    ;BB
    retlw   ' '    ;BC
    retlw   ' '    ;BD
    retlw   ' '    ;BE
    retlw   ' '    ;BF
    retlw   ' '    ;C0
    retlw   ' '    ;C1
    retlw   ' '    ;C2
    retlw   ' '    ;C3
    retlw   ' '    ;C4
    retlw   ' '    ;C5
    retlw   ' '    ;C6
    retlw   ' '    ;C7
    retlw   ' '    ;C8
    retlw   ' '    ;C9
    retlw   ' '    ;CA
    retlw   ' '    ;CB
    retlw   ' '    ;CC
    retlw   ' '    ;CD
    retlw   ' '    ;CE
    retlw   ' '    ;CF
    retlw   ' '    ;D0
    retlw   ' '    ;D1
    retlw   ' '    ;D2
    retlw   ' '    ;D3
    retlw   ' '    ;D4
    retlw   ' '    ;D5
    retlw   ' '    ;D6
    retlw   ' '    ;D7
    retlw   ' '    ;D8
    retlw   ' '    ;D9
	retlw	0x00
AlphaD
	addwf	PCL, f
    retlw   ' '    ;DA
    retlw   ' '    ;DB
    retlw   ' '    ;DC
    retlw   ' '    ;DD
    retlw   ' '    ;DE
    retlw   ' '    ;DF
    retlw   ' '    ;E0
    retlw   ' '    ;E1
    retlw   ' '    ;E2
    retlw   ' '    ;E3
    retlw   ' '    ;E4
    retlw   ' '    ;E5
    retlw   ' '    ;E6
    retlw   ' '    ;E7
    retlw   ' '    ;E8
    retlw   ' '    ;E9
    retlw   ' '    ;EA
    retlw   ' '    ;EB
    retlw   ' '    ;EC
    retlw   ' '    ;ED
    retlw   ' '    ;EE
    retlw   ' '    ;EF
    retlw   ' '    ;F0
    retlw   ' '    ;F1
    retlw   ' '    ;F2
    retlw   ' '    ;F3
    retlw   ' '    ;F4
    retlw   ' '    ;F5
    retlw   ' '    ;F6
    retlw   ' '    ;F7
    retlw   ' '    ;F8
    retlw   ' '    ;F9
    retlw   ' '    ;FA
    retlw   ' '    ;FB
    retlw   ' '    ;FC
    retlw   ' '    ;FD
    retlw   ' '    ;FE
    retlw   ' '    ;FF
	retlw	0x00

Init:
	movlw	0x72
	movwf	OSCCON			;8 Mhz

	movlw	0x0F
	movwf	ADCON1			;All Digital

	bcf		kbt, kb_dat		;make kb data line ouput
	bcf		kbt, kb_clk		;make kb clock line ouput


	call	Delay100uS
	movlw	0xF4
	call	SendKB
	call	Delay100uS
	clrf	pntr
Main:
	call	GetKB

	bra		Main

GetKB:
    MOVLW   0x08                  ;set up to read 8 bits
    MOVWF   count
    CLRF    kbdata

    btfsc   kb, kb_clk
	bra		$-2
    btfss   kb, kb_clk
	bra	$-2
    btfsc   kb, kb_clk
	bra	$-2

MyByte: 
	;call	Delay10us

    btfss   kb, kb_dat
	bcf		kbdata,7
    btfsc   kb, kb_dat
	bsf		kbdata,7

    rrncf    kbdata, f

    btfss   kb, kb_clk
	bra	$-2
    btfsc   kb, kb_clk
	bra	$-2

    decfsz  count  , f         ;test if all done
	goto 	MyByte

	call	Delay40uS
	call	Delay40uS
	call	Delay40uS
	call	Delay40uS

	;movlw	0x70
	;cpfseq	kbdata
	;bra		$+4
	;goto	startget

	movf	kbdata, W

	movlw	0xD9
	cpfsgt  kbdata
	bra		$+6
	subwf	kbdata, 0
	call	AlphaD

	movlw	0x99
	cpfsgt  kbdata
	bra		$+6
	subwf	kbdata, 0
	call	AlphaC

	movlw	0x49
	cpfsgt  kbdata
	bra		$+6
	subwf	kbdata, 0
	call	AlphaB

	movlw	0x4A
	cpfslt  kbdata
	bra		$+6
	movf	kbdata
	call	AlphaA

doneA:


	movlw 	somedata ;set starting address of my table
	addwf	pntr,0
	movwf	FSR0L
	movf	kbdata, W
	movwf	INDF0
	incf 	pntr

	call	Delay300mS
    RETURN

SendKB:
	bcf		kbt, kb_dat
	bcf		kbt, kb_clk
	clrf	count

	movwf	Xmit_Byte
	movff	Xmit_Byte,parity

	movlw	0x08
	movwf	count
d_loop:
	rrcf	Xmit_Byte, 1
	btfss	STATUS, C
	call	SendZero
	btfsc	STATUS, C
	call	SendOne
	
	decfsz	count
	goto	d_loop

;ParityTest
	CALC_PARITY parity
	btfsc	parity,0
	call	SendZero
	btfss	parity,0
	call	SendOne

;StopBit
	call	SendOne

	bsf		kbt, kb_dat		;make kb data line input
	bsf		kbt, kb_clk		;make kb clock line input
	return

SendOne:
	bcf		kbl, kb_clk
	bsf		kbl, kb_dat
	call	Delay40uS
	bsf		kbl, kb_clk
	return
SendZero:
	bcf		kbl, kb_clk
	bcf		kbl, kb_dat
	call	Delay40uS
	bsf		kbl, kb_clk
	return
Delay300mS
	movlw	0xD1
	movwf	d1
	movlw	0x4F
	movwf	d2
	movlw	0x02
	movwf	d3
Delay300mS_0
	decfsz	d1, f
	goto	$+6
	decfsz	d2, f
	goto	$+6
	decfsz	d3, f
	goto	Delay300mS_0
	return

Delay10us
	movlw	0x10
	movwf	d1
Delay30us_0
	decfsz	d1, f
	goto	Delay30us_0
	nop
	return

Delay50mS
	movlw	0x1E
	movwf	d1
	movlw	0x4F
	movwf	d2
Delay50mS_0
	decfsz	d1, f
	goto	$+6
	decfsz	d2, f
	goto	Delay50mS_0
	goto	$+2
	nop
	return

	
Delay100uS
	movlw	0x41
	movwf	d1
Delay100uS_0
	decfsz	d1, f
	goto	Delay100uS_0
	return

Delay40uS
	movlw	0x19
	movwf	d1
Delay40uS_0
	decfsz	d1, f
	goto	Delay40uS_0
	return
Delay1S
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
Delay1S_0
	decfsz	d1, f
	goto	$+6
	decfsz	d2, f
	goto	$+6
	decfsz	d3, f
	goto	Delay1S_0
	return

HighInt:
	retfie	FAST

		END
 

Mike - K8LH

Well-Known Member
You can do tables with 'dt' directive or individual 'retlw' lines on the 18F' but people often forget that the index value must be multiplied by 2 before applying it or adding it to the program counter registers.

You might also consider using the TBLPTR mechanism to access rom tables.

Mike
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
You can do tables with 'dt' directive or individual 'retlw' lines on the 18F' but people often forget that the index value must be multiplied by 2 before applying it or adding it to the program counter registers.
I knew there was something! :D

You might also consider using the TBLPTR mechanism to access rom tables.
That was what I did, doubling the index seemed far too wasteful of space.
 

Mike - K8LH

Well-Known Member
Well not only that but the 'retlw' table uses a whole 16-bit word for each table entry where the 'db' or 'dw' (TBLPTR) tables store two bytes in each word so the tables use half the memory space.

Mike
 

ericgibbs

Well-Known Member
Most Helpful Member
I guess i got stuck in 16F mode lol
ok im lost can someone make a sample table with like 2 entries.

i will take it from there.
hi atom,

Have you read Section 6 of the 18F2525 datasheet ref Tables.?
 

AtomSoft

Well-Known Member
call me stupid and lazy lol i tried to do this but no luck. It doesnt add right. I assumed if i add to TBLPTR itself it would increase the whole 24bits. But no luck.

Code:
		movlw	upper MyTable
		movwf	TBLPTRU
		movwf	high MyTable
		movwf	TBLPTRH
		movlw	low MyTable
		movwf	TBLPTRL
	
		;repeat the following lines as necessary
		movf	kbdata, W
		addwf	TBLPTR
		tblrd	*+		;use TBLPTRU:TBLPTRH:TBLPTRL as 24-bit pointer to memory
		movf	TABLAT,w	;place value pointed to in W
I guess oi have to make another loop now lol
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top