Heckler, bless your heart.
Like I said, it would help if I read a bit better --- should go to bed.
Since your the Teacher then here:
Question: does your suggestions apply to writing out to the pins as well as reading in from the pins
From the same pins? Yes, you would read what you set AND any INPUTs -- all assuming the TRIS[a,b,c] are set properly
If you need to write to other pins and maintain the LEDs then see
"OTHER_PIN_STATES"
Yes, these will write directly to the ports.
Using this order for what you want displayed in a byte
A1,A2,C0,C1,C2,B4,B5,B6
And the final value is stored in the LED_OUT a VAR BYTE
You will need to take care of the TRIS registers.
Code:
PortA = (LED_OUT & %00000011) << 1 ' get bits a1, a2 and shift UP 1 to PORTA.1.2
PortC = (LED_OUT & %00011100) >> 2 ' get bits C0,C1,C2 and shift DOWN 2 to PORTC.0.1.2
PortB = (LED_OUT & %11100000) >> 1 ' get bits B4,B5,B6 and shift DOWN 1 to PORTB.4.5.6
"OTHER_PIN_STATES"
If you need to keep other pins 'On or off' then use
Code:
PortB = OTHER_PIN_STATES + (LED_OUT & %11100000) >> 1
Input would be the the reverse.
Try this for an INPUT
Using this order
A1,A2,C0,C1,C2,B4,B5,B6
Code:
KEY_8x8 = ((PortA & $06) >> 1) + ((PortC & $07) << 2) + ((PortB & $70) << 1)
or
KEY_8x8 = (PortA & %00000110) >> + ((PortC & %00000111) << 2) + ((PortB & %01110000) << 1)
PortA.1.2 are extracted and shifted down one to bits %xxxxxxAA
PortC.0.1.2 are extracted and shifted to up two bits %xxxxBBBxx
PortB.4.5.6 are extracted and shifted to up one bit %CCCxxxxxx
OTHER hints be sure to set the -- I keep forgetting then spending to much time finding that goof.
Code:
' setup the registers and IO PINS
'— COMPARATOR CONTROL REGISTER -- choose the correct one for your chip :o)
CMCON = $07 'CMCON — COMPARATOR CONTROL REGISTER ALL DIGITAL
'or
' CMCON0 = $07 'ALL DIGITAL 12f683 & chips with a2d — COMPARATOR CONTROL REGISTER
'
' ADCON1 = %01100000 ' Set a2d convert at clk/6 [slowest]
' ADCON1 = %00000000 ' Set a2d convert at clk/2 [fastest]
ANSEL = %00000000 ' AN0/RA0 as analog input 1=ANALOG
ADCON0 = %00000000 ' .7=10bits left justify result!! / .0 1=a2d ON
and Pull-up the _MCLR PIN !!!!
Bookmarks