PDA

View Full Version : Help me out..



Joann
- 22nd February 2007, 10:30
I need a help from members,to help me show me how i can use at/ps2 keyboard to enter text or data to the eeprom memory of the pic16f877a ,the code is attached and it works very fine for led sign display i was using pc to enter the text,
****************

DEFINE OSC 10 ' Oscillator speed in MHz: 3(3.58) 4 8 10 12 16 20 25 32 33 40
Include "modedefs.bas" ' Include serial modes
@ DEVICE PIC16F877A,HS_OSC,WDT_OFF,PWRT_ON,LVP_OFF,BOD_OFF
CMCON = 7
ADCON1 = 7

TRISB = 0 ' Setup PortB = outputs module selection data
TRISD = 0 ' Setup PortD = outputs the data word and address of module

TRISA.2 = 0 : TRISA.1 = 0 : TRISA.0 = 0

databits var PORTA.2 ' clock signal for the character segment data IC
addsbits var PORTA.1 ' clock signal for the char. segment address data IC
modsbits var PORTA.0 ' clock signal for the module select IC

Addss VAR BYTE[8] ' 8-byte address array
Mods VAR BYTE[8] ' 8-byte address array
Datas var byte[64]' array to keep the ever changing character segments
loops con 2 ' number of frame loops, for flicker-free effect
columns con 63 ' columns + 1 = number of columns on the display, starts from 0 to 63 = 64
module con 8 ' number of modules and columns on modules 8 x 8, indicates when to go to next module and when to start from beginning of module
EOM con "" ' Character used as "End of Message" marker
SPA con $D ' Character used as "End of Message" marker

character_segment VAR BYTE ' data word for LED matrix
column_select VAR BYTE ' variable that keeps track if one module length was exceeded
module_select VAR BYTE ' variable that keeps track of which module should be activated

i VAR BYTE ' for loop pointer
iTMP var byte ' points to the char. segment that will start out the new scroll
char var byte ' points to the char. that will be seperated into segments for display
charTMP var byte ' points to the char that will start out the new scroll
ColumnAddress VAR BYTE ' pointer that indexes which column in module is to be addressed
LoopDisplay var byte ' pointer that indexes how many times the screen has been looped
char2disp var byte ' variable that gets the character to display
NEWcharflag var byte ' indicates that new char. needs to be displayed on start of next refresh
message var byte ' stores how many columns have been taken up by message, scrolling message will = 63, message shorter than the lenght of sigh <= 62.
displayme var word ' pause between each lighting of LEDs, in microseconds


''''' S T O R E A D D R E S S S E Q U E N C E S IN A R R A Y S ''''''''
FOR i = 0 TO 7
' LOOKUP i,[$01,$02,$04,$08,$10,$20,$40,$80],module_select 'used with NPN transistors
LOOKUP i,[$FE,$FD,$FB,$F7,$EF,$DF,$BF,$7F],module_select 'used with MIC5801 ICs & DM74ALS574 ICs
Mods[i] = module_select ' Load all 8 addresses into array

LOOKUP i,[$10,$20,$40,$80,$01,$02,$04,$08],column_select
Addss[i] = column_select ' Load all 8 addresses into array
NEXT i

''''' S T O R E C H A R A C T E R S E G M E N T S I N A R R A Y ''''''
start: ' very start of the whole loop, this point will reset all variabled, and will start on a clean start

char = 0 : charTMP = 0 : i = 0 : iTMP = 0 : NEWcharflag = 0 : 'reset all necessary variables
message = columns

MoveDataByOneColumn: 'the data display stars here

i = iTMP : char = charTMP 'set the character segment and character to start out the display with
NEWcharflag = 0 'reset the flag which indicates to start out with new character when the display stars scrolling

FOR ColumnAddress = 0 TO columns 'store max. no. of segments in the data array, which is 64


READ char,char2disp 'read a character from the eeprom memory

'check if the character from the eeprom memory is a lower/upper case char. or a number or a special char.
'then grab its' segment data from the 4 lookup tables containing all character
If (char2disp >= "A") and (char2disp <= "Z") then
goto UPPERcase
endif

If (char2disp >= "a") and (char2disp <= "z") then
goto LOWERcase
else
goto OTHERcase
endif
'done checking the character format, and grabbing its' segment values

donecharacterlookup: 'done looking up the character data

IF character_segment = EOM THEN 'check to see if end of character
character_segment = $FF 'yes, so replace it with a blank, so there is a blank after each character
char = char + 1 'increment pointer to next character in message
i = 0 'reset index pointer that points to which char. segment to display
if (ColumnAddress = 0) then 'check to see if this is the first time we're looping, we do not want to do this 64 times!
charTMP = charTMP + 1 'increment the character pointer to next character, the next time the screen displays
iTMP = 0 'reset index pointer that points which char. segment to display, next time the screen displays
NEWcharflag = 1 'set a flag which indicates that new character must be displayed next time the screen displays
endif 'end if
else 'no, not the end of character
i = i + 1 'increment pointer to the next char. segment of the character displaying
endif 'done checking character segments

Datas[ColumnAddress] = character_segment 'store the segment in the character segment array

NEXT ColumnAddress 'do this 64 times to fill up the whole character segment array

if NEWcharflag = 0 then 'check to see if the 'new character' flag was set
iTMP = iTMP + 1 'no, so increment the pointer to point to new char. segment of character, next time the screen displays
endif 'done incrementing pointer of character segments

goto startDISPLAY

fillDISPLAY:
iTMP = 0 : charTMP = 0 : NEWcharflag = 0 ': GOTO MoveDataByOneColumn
message = ColumnAddress 'store the message lenght to calculate the refresh rate later on

for i = ColumnAddress TO columns 'fill up the data array with blanks if message is shorter than the length of the SIGN


Datas[i] = $FF 'if message is shorter then the lenght of the SIGN, fill up rest of the columns with blanks
next i

mister_e
- 22nd February 2007, 21:31
to read a PS2 keyboard, you need something like...


'
' PS2 Keypad signal
' -----------------
DEFINE PS2_SCLK PORTC
DEFINE PS2_SCLK_BIT 1
DEFINE PS2_SDATA PORTC
DEFINE PS2_SDATA_BIT 0

'
' Variables definition
' ====================
KeyPS2 var BYTE ' Store pressed key


' some code here


'
' Keypad scan routine
' ===================
ReadPS2: '
' data is packed in a 11 Bit format
' Start, 8 bit data(LSB first), 1 parity, 1 stop.
'
' data is available on the falling edge of the clk
'
gotsync=0 ' No synch received

ScanIt:
ASM
CHK?RP PS2_SCLK
CALL SkipPulse ; Skip the start bit
CLRF _BitCounter ; clear bit counter

ReadLoop
BTFSC PS2_SCLK,PS2_SCLK_BIT ; wait for clk falling edge
GOTO $-1 ;
ENDASM

@ MOVE?TB PS2_SDATA,PS2_SDATA_BIT,_SDATA
KeyPS2.0[BitCounter]=SDATA ; Save current bit value

ASM
BTFSS PS2_SCLK,PS2_SCLK_BIT ; wait for clk falling edge
GOTO $-1 ;

INCF _BitCounter,F ; increment bit counter

MOVLW 8 ;
XORWF _BitCounter,W ; check if = 8 (end)
BTFSS STATUS,Z ;
GOTO ReadLoop ; if not read again

CALL SkipPulse ; skip parity
CALL SkipPulse ; skip stop bit
GOTO GetOut ; get out of here to test the
; actual result

SkipPulse
BTFSC PS2_SCLK,PS2_SCLK_BIT ; wait for falling edge
GOTO $-1 ;

BTFSS PS2_SCLK,PS2_SCLK_BIT ; wait for rising edge
GOTO $-1 ;

RETURN ; Bye bye!

GetOut
ENDASM

Then, you need to build a HUGE lookup table and + conditions to fit the PS2 ScanCode which is store in KeyPS2 variable.

The above don't check the parity, don't check the validity of the Start bit... it's just a plain and starter version.... sorry if it's mostly in ASM..

In PBP it should be something close to...


ReadPS2:
FOR COUNTERBIT=0 TO 10
WaitFallingEdge: if sclk then waitfallingedge
KEY.0[COUNTERBit]=SDATA
WaitRisingEdge: if sclk=0 then waitrisingedge
NEXT
KEY=(KEY>>1)&$ff
return

there's few other example here and there in the forum. Melanie also draw the whole PC ScanCode table.

at least
http://www.picbasic.co.uk/forum/showthread.php?t=2736&highlight=ps2%2A
http://www.picbasic.co.uk/forum/showthread.php?t=81&highlight=scan+code

Joann
- 24th February 2007, 11:34
Thank you Steve, for your concern i will give it a try and get back to you, mostly to use ps2 keyboard is good for the moving sign display as it serves as stand alone with out pc,when you plug the key board you just hit any funtion key like f1 to enter data,f2 to delete,and f3 to store the data etc, that will be fine for me .

Joann
- 27th February 2007, 12:48
hello steve ,
i have try it without success.
anymore idea.

T.Jackson
- 27th February 2007, 13:02
hello steve ,
i have try it without success.
anymore idea.

Perhaps you could post a schematic of what you have done? This may help others in helping you since the suggested code you have been offered is to be known as working.

Best Regards,

Trent Jackson