Continue to Site

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.

  • 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.
yes you are correct Burt but wouldnt it be nice to be able to set all the other settings via keyboard. Other settings meaning: Speed, Brighness, Orientation and of course text. I would love to use a GLCD or Char LCD for that since i can have many lines.
 
thanks Mike! I will be make my own PS/2 Library now. Like turning that ASM into a usable C Function and the delays into something that can be calculated using something like a

#define Clock 8
 
I have a old led sign that used a a keypad for all that it had A to Z and - , . / # keys
I took it apart for the leds modules and driver chips the keypad got lost and no one made one like it. That great job Atom
 
Thanks! By the end of today i will have a nice library done. And you know whats the best part?......... .........Its free!


Ill make a PDF for it like "mikroElektronika" does... It will have a little sample and information on commands (there will be a send command to the KB maybe for leds) and a schematic for showing how i connected it and tested it.
 
Jason,

Been studying your code and have a question. You set bit 7 in kbdata to the current data bit and then rotate the byte (rrncf) so after 8 iterations you end up with the very first received bit in the bit 7 position. Is that what you intended?

I was thinking that the first bit collected should end up being bit 0 in the kbdata variable but I admit I know absolutely nothing about the keyboard data format.

Also, why are you using ASM code in your C program and why are you clearing bits in kbdata that are already clear?

Code:
#define KBD_CLK portc.2
#define KBD_DAT portc.1

 unsigned char GetKey()           //
 { unsigned char kbdata = 0;      //
   while(KBD_CLK == 1);           // wait for KBD_CLK to go 'lo'
   for(i = 0; i < 8; i++)         // collect 8 data bits
   { kbdata >>= 1;                // shift previous bit to right
     while(KBD_CLK == 0);         // wait for KBD_CLK to go 'hi'
     while(KBD_CLK == 1);         // wait for KBD_CLK to go 'lo'
     if(KBD_DAT) kbdata.7 = 1;    // collect data bit
   }
   ........
   return(KeyMap[kbdata]);        // return table character
 }
 
Last edited:
wow i never noticed that lol but heh it works well tho. I get nice results anyway.

im sure doing the below would be the correct way i assume:
Code:
    rrncf    kbdata, 1,1

    btfss   PORTC, 1,0
	bcf		kbdata,7,1
    btfsc   PORTC, 1,0
	bsf		kbdata,7,1

But if it works why fix it? lol If anything ill fix it later on but then i have to change all cases in the switch lol which is easy anyway
 
Ok, so you're collecting 8 bits of data and not really paying attention to how they go into the 'kbdata' variable. You still end up with 256 unique values for an index into the key map array so it doesn't matter.

That's cool... Did you see the sample code I added to my previous post?
 
Ill try that code now. I was using asm because i wasnt sure if the C code takes to long to process and i would mistakenly skip a pulse and get the wrong data.

I was clearing the bits because i wasnt sure if i cleared the whole KBDATA variable after i used it hence it will contain the old data from before. But im sure i can just clear the variable upon entry.

I guess ima lazy guy lol thanks again. Ima try the code now.
 
Ok i altered your code to:

Code:
   	while(kb_cr == 1);           // wait for KBD_CLK to go 'lo'
   	for(i = 0; i < 8; i++)         // collect 8 data bits
	{
     	while(kb_cr == 0);         // wait for KBD_CLK to go 'hi'
     	while(kb_cr == 1);         // wait for KBD_CLK to go 'lo'
     	if(kb_dr) kbdata |= 0x80;    // collect data bit
		kbdata >>= 1;                // shift previous bit to right
   	}
I had these already defined:
Code:
	#define kb_dr	PORTCbits.RC1
	#define kb_dw	LATCbits.LATC1

	#define kb_cr	PORTCbits.RC2
	#define kb_cw	LATCbits.LATC2

I changed your kbdata.7 = 1 because it didnt work. im on c18 and it gave an error so its now
Code:
if(kb_dr) kbdata |= 0x80;

I placed
Code:
kbdata >>= 1;
At the end so it would match my code so i can test.

The issue now is that i get some keys that are the same. like

j and m key are both 0x1D. I know in my code m=0x1D and j=0x9D so i can assume its not getting the last bit..

I tried changing it to
Code:
	while(kb_cr == 1);			// wait for KBD_CLK to go 'lo'
	while(kb_cr == 0);			// wait for KBD_CLK to go 'hi'
	while(kb_cr == 1);			// wait for KBD_CLK to go 'lo'

	for(i = 0; i < 8; i++)		// collect 8 data bits
	{
		if(kb_dr == 1) kbdata |= 0x80;	// collect data bit
		kbdata >>= 1;					// shift previous bit to right
		while(kb_cr == 0);				// wait for KBD_CLK to go 'hi'
		while(kb_cr == 1);				// wait for KBD_CLK to go 'lo'
	}

since it sends a start bit i have to skip it. Then get 8 bits. The issue is this still gives me keys with the same values.

Thats why i used inline ASM. I doesnt fail :D i think i should continue to use the ASM tho. Its ok
 
Last edited:
Ah, there's a <start> bit. That explains a lot. Are there any other bits besides the <start> bit and 8 data bits?
 
yeah a PARITY AND STOP bit lol but i skip those. You need them in a write tho.. heh i have a keyboards datasheet. but i just found this site.

**broken link removed**

Basic Info:

* 1 start bit. This is always 0.
* 8 data bits, least significant bit first.
* 1 parity bit (odd parity).
* 1 stop bit. This is always 1.


The Data line changes state when Clock is high and that data is valid when Clock is low.
 
Last edited:
dude you was right tho lol:
Code:
GetKB:
_asm
A:
	btfsc   PORTC, 2,0
	bra		A
B:
	btfss   PORTC, 2,0
	bra		B
C:
	btfsc   PORTC, 2,0
	bra		C
MyByte: 
	rrncf	kbdata, 1,1
	btfss	PORTC, 1,0
	bcf		kbdata,7,1
	btfsc	PORTC, 1,0
	bsf		kbdata,7,1
D:
	btfss	PORTC, 2,0
	bra		D
E:
	btfsc	PORTC, 2,0
	bra		E

	decfsz	count  , 1,1      
	bra		MyByte
_endasm

this is the asm way with the rotate before the collect. It gives me a 0x15 aka 15h with the letter Q lol.

I should fix it then lol im still gonna use the ASM but the right way with that ROTATION fix you noticed. Thanks
 
Last edited:
I think I would do it this way which shifts the <start> bit out of the kbdata variable (exactly the way you're doing it in your original program code);

Code:
 unsigned char GetKey()          //
 { unsigned char kbdata = 0;     //
   while(kb_cr == 1);            // wait for CLK pin 'hi'
   for(i = 0; i < 9; i++)        // <start> and 8 <data> bits
   { while(kb_cr == 0);          // wait for CLK pin 'hi'
     while(kb_cr == 1);          // wait for CLK pin 'lo'
     kbdata >>= 1;               // shift bits to right
     if(kb_dr) kbdata |= 128;    // add bit to kbdata
   }
   while(kb_cr == 0);            // throw away <parity> bit
   while(kb_cr == 1);            //
   while(kb_cr == 0);            // throw away <stop> bit
   while(kb_cr == 1);            //
   ........
As for the efficiency of the C code, that's why you need to look at the assembler instructions in the LST file. The code above generates almost the same assembler instructions that I would use if I were writing the code in assembler to begin with. And remember, the reason we're writing it in C is to help make it easier for others who don't know assembler to understand what we're doin'.

Later, Mike
 
Code:
//I took out the first WHILE() loop since it doesnt do anything really lol
//kbdata is a global i use.
   for(i = 0; i < 9; i++)        // <start> and 8 <data> bits
   { while(kb_cr == 0);          // wait for CLK pin 'hi'
     while(kb_cr == 1);          // wait for CLK pin 'lo'
     kbdata >>= 1;               // shift bits to right
     if(kb_dr) kbdata |= 128;    // add bit to kbdata
   }
   while(kb_cr == 0);            // throw away <parity> bit
   while(kb_cr == 1);            //
   while(kb_cr == 0);            // throw away <stop> bit
   while(kb_cr == 1);            //

This works well... thanks!
 
Well you still want to clear kbdata at the start of the function even if it's global...

I don't think you need to change your Map array because your original code was throwing away the <start> bit too...

Later, Mike
 
Everything works well now. The only issue is hardware. I see why i get alot of bad feedback from keyboard. Its because a keyboard it like a film inside its a plastic which needs to be clean lol.
I got like 5 keyboards from a friend and they are kinda old and dirty so i guess thats why i have some issues. I need to try a new one lol.

You thing a keyboard with a USB to PS/2 Adapter would work here?
 
Oops!!! here is my full code.... ill make library type files later:

Code:
/* *****************************************************************************
;                                                                             *
;    Filename:                     				                              *
;    Date:                                         	                          *
;    File Version: 001                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;***************************************************************************** */

#include <p18f2525.h>
#include <delays.h>
#include <string.h>

#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF

/************************************
Prototypes
*************************************/
void main(void);
void LCDString(rom unsigned char *str);
void InitLCD(void);
void LCDLine(unsigned char line);
void SendLCD(unsigned char dat,unsigned char RSV);
void ToggleE(void);

unsigned char GetKey(void);
/************************************
Variables and Defines
*************************************/
	unsigned char tempKey;
	unsigned char a2z[104];
	unsigned char shiftcap = 0;

	unsigned char count;
 	unsigned char kbdata;
//Keyboard Defines
	#define kbt_d	TRISCbits.TRISC1
	#define kbt_c	TRISCbits.TRISC2

	#define kb_dr	PORTCbits.RC1
	#define kb_dw	LATCbits.LATC1

	#define kb_cr	PORTCbits.RC2
	#define kb_cw	LATCbits.LATC2

//LCD Defines
	#define LCDt	TRISB
	#define LCD		PORTB
	#define RS		LATBbits.LATB4
	#define ET		LATBbits.LATB5

/************************************
Main
*************************************/
void main(void){

	OSCCON = 0x72;      			//8MHz clock
	while(!OSCCONbits.IOFS);		//wait for osc stable

	kbt_d = 1;		//Keyboard Data Tris is INPUT
	kbt_c = 1;		//Keyboard Clock Tris is INPUT

	InitLCD();
	LCDString((rom unsigned char*)"AtomSoftTech.");
	LCDLine(2);
	//LCDString((rom unsigned char*)"Keyboard Test");

	//a2zi = 0;
	while(1){
		tempKey = GetKey();
		if(tempKey >= 0x20) 
			if(tempKey <= 0x7E){
				if(shiftcap >= 1){
					 if(tempKey >= 0x61)
						if(tempKey <= 0x7A)
							tempKey -= 0x20;

					 if(shiftcap == 1)
						shiftcap = 0;
				}

				SendLCD(tempKey,1);
				Delay10KTCYx(100); 		//500mS
			}

		if(tempKey == 0x08){
			SendLCD(0x10,0);
			Delay1KTCYx(16);

			SendLCD(0x20,1);
			Delay1KTCYx(16);

			SendLCD(0x10,0);
			Delay1KTCYx(16);
			Delay10KTCYx(60); 		//500mS
		}

		if(tempKey == 0)
			Delay10KTCYx(100); 		//500mS
			
		//a2z[a2zi++] = tempKey;

	}
}

unsigned char GetKey(void){
	char i;
	kbdata = 0;

   for(i = 0; i < 9; i++)        // <start> and 8 <data> bits
   { 
	 while(kb_cr == 0);          // wait for CLK pin 'hi'
     while(kb_cr == 1);          // wait for CLK pin 'lo'
     kbdata >>= 1;               // shift bits to right
     if(kb_dr) kbdata |= 128;    // add bit to kbdata
   }
   while(kb_cr == 0);            // throw away <parity> bit
   while(kb_cr == 1);            //
   while(kb_cr == 0);            // throw away <stop> bit
   while(kb_cr == 1);            //


Delay10TCYx(70); 		//Delay 320uS aka 2 clocks(bits)

	//return tmp;
	switch(kbdata){
        case 0x00:
            return 0x00;
        case 0x01:
            return 0x00;
        case 0x02:
            return 0x00;
        case 0x03:
            return 0x00;
        case 0x04:
            return 0x00;
        case 0x05:
            return 0x00;
        case 0x06:
            return 0x00;
        case 0x07:
            return 0x00;
        case 0x08:
            return 0x00;
        case 0x09:
            return 0x00;
        case 0x0A:
            return 0x00;
        case 0x0B:
            return 0x00;
        case 0x0C:
            return 0x00;
        case 0x0D:
            return 0x09;
        case 0x0E:
			if(shiftcap == 0)
            	return 0x60;
			else
				return 0x7E;
        case 0x0F:
            return 0x00;
        case 0x10:
            return 0x00;
        case 0x11:
            return 0x00;
        case 0x12:
            shiftcap = 1;
            return 0x00;
        case 0x13:
            return 0x00;
        case 0x14:
            return 0x00;
        case 0x15:
            return 'q';
        case 0x16:
			if(shiftcap == 0)
            	return '1';
			else
				return 0x21;
        case 0x17:
            return 0x00;
        case 0x18:
            return 0x00;
        case 0x19:
            return 0x00;
        case 0x1A:
            return 'z';
        case 0x1B:
            return 's';
        case 0x1C:
            return 'a';
        case 0x1D:
            return 'w';
        case 0x1E:
			if(shiftcap == 0)
            	return '2';
			else
				return 0x40;
        case 0x1F:
			if(shiftcap == 0)
            	return '8';
			else
				return 0x2A;
        case 0x20:
            return 0x00;
        case 0x21:
            return 'c';
        case 0x22:
            return 'x';
        case 0x23:
            return 'd';
        case 0x24:
            return 'e';
        case 0x25:
			if(shiftcap == 0)
            	return '4';
			else
				return 0x24;
        case 0x26:
			if(shiftcap == 0)
            	return '3';
			else
				return 0x23;
        case 0x27:
            return '-';
        case 0x28:
            return 0x00;
        case 0x29:
            return ' ';
        case 0x2A:
            return 'v';
        case 0x2B:
            return 'f';
        case 0x2C:
            return 't';
        case 0x2D:
            return 'r';
        case 0x2E:
			if(shiftcap == 0)
            	return '5';
			else
				return 0x25;
        case 0x2F:
            return 0x00;
        case 0x30:
            return 0x00;
        case 0x31:
            return 'n';
        case 0x32:
            return 'b';
        case 0x33:
            return 'h';
        case 0x34:
            return 'g';
        case 0x35:
            return 'y';
        case 0x36:
			if(shiftcap == 0)
            	return '6';
			else
				return 0x5E;
        case 0x37:
            return 0x00;
        case 0x38:
            return 0x00;
        case 0x39:
            return 0x00;
        case 0x3A:
            return 'm';
        case 0x3B:
            return 'j';
        case 0x3C:
            return 'u';
        case 0x3D:
            return 0x00;
        case 0x3E:
            return '8';
        case 0x3F:
            return 0x00;
        case 0x40:
            return 0x00;
        case 0x41:
			if(shiftcap == 0)
            	return ',';
			else
				return '<';
        case 0x42:
            return 'k';
        case 0x43:
            return 'i';
        case 0x44:
            return 'o';
        case 0x45:
			if(shiftcap == 0)
            	return '0';
			else
				return ')';
        case 0x46:
			if(shiftcap == 0)
            	return '9';
			else
				return '(';
        case 0x47:
            return 0x00;
        case 0x48:
            return 0x00;
        case 0x49:
			if(shiftcap == 0)
            	return '.';
			else
				return '>';
        case 0x4A:
			if(shiftcap == 0)
            	return '/';
			else
				return '?';
        case 0x4B:
            return 'l';
        case 0x4C:
			if(shiftcap == 0)
            	return ';';
			else
				return ':';
        case 0x4D:
            return 'p';
        case 0x4E:
			if(shiftcap == 0)
            	return '-';
			else
				return '_';
        case 0x4F:
            return 0x00;
        case 0x50:
            return 0x00;
        case 0x51:
            return 0x00;
        case 0x52:
			if(shiftcap == 0)
            	return 0x2C;
			else
				return '"';
        case 0x53:
            return 0x00;
        case 0x54:
			if(shiftcap == 0)
            	return '[';
			else
				return '{';
        case 0x55:
			if(shiftcap == 0)
            	return '=';
			else
				return '+';
        case 0x56:
            return 0x00;
        case 0x57:
            return 0x00;
        case 0x58:
            if(shiftcap == 2)
                shiftcap = 0;
            else
                shiftcap = 2;
            return 0x00;
        case 0x59:
            shiftcap = 1;
            return 0x00;
        case 0x5A:
            return 0x0A; //Line Feed :D
        case 0x5B:
			if(shiftcap == 0)
            	return ']';
			else
				return '}';
        case 0x5C:
            return 0x00;
        case 0x5D:
			if(shiftcap == 0)
            	return 0x5C;
			else
				return '|';
        case 0x5E:
            return 0x00;
        case 0x5F:
            return 0x00;
        case 0x60:
            return 0x00;
        case 0x61:
            return 0x00;
        case 0x62:
            return 0x00;
        case 0x63:
            return 0x00;
        case 0x64:
            return 0x00;
        case 0x65:
            return 0x00;
        case 0x66:
            return 0x08;
        case 0x67:
            return 0x00;
        case 0x68:
            return 0x00;
        case 0x69:
            return 0x00;
        case 0x6A:
            return 0x00;
        case 0x6B:
            return 0x00;
        case 0x6C:
            return 0x00;
        case 0x6D:
            return 0x00;
        case 0x6E:
            return 0x00;
        case 0x6F:
            return 0x00;
        case 0x70:
            return 0x00;
        case 0x71:
            return 0x00;
        case 0x72:
            return 0x00;
        case 0x73:
            return 0x00;
        case 0x74:
            return 0x00;
        case 0x75:
            return 0x00;
        case 0x76:
            return 0x00;
        case 0x77:
            return 0x00;
        case 0x78:
            return 0x00;
        case 0x79:
            return 0x00;
        case 0x7A:
            return 0x00;
        case 0x7B:
            return 0x00;
        case 0x7C:
            return 0x00;
        case 0x7D:
            return 0x00;
        case 0x7E:
            return 0x00;
        case 0x7F:
            return 0x00;
        case 0x80:
            return 0x00;
        case 0x81:
            return 0x00;
        case 0x82:
            return 0x00;
        case 0x83:
            return 0x00;
        case 0x84:
            return 0x00;
        case 0x85:
            return 0x00;
        case 0x86:
            return 0x00;
        case 0x87:
            return 0x00;
        case 0x88:
            return 0x00;
        case 0x89:
            return 0x00;
        case 0x8A:
            return 0x00;
        case 0x8B:
            return 0x00;
        case 0x8C:
            return 0x00;
        case 0x8D:
            return 0x00;
        case 0x8E:
            return 0x00;
        case 0x8F:
            return 0x00;
        case 0x90:
            return 0x00;
        case 0x91:
            return 0x00;
        case 0x92:
            return 0x00;
        case 0x93:
            return 0x00;
        case 0x94:
            return 0x00;
        case 0x95:
            return 0x00;
        case 0x96:
            return 0x00;
        case 0x97:
            return 0x00;
        case 0x98:
            return 0x00;
        case 0x99:
            return 0x00;
        case 0x9A:
            return 0x00;
        case 0x9B:
            return 0x00;
        case 0x9C:
            return 0x00;
        case 0x9D:
            return 0x00;
        case 0x9E:
            return 0x00;
        case 0x9F:
            return 0x00;
        case 0xA0:
            return 0x00;
        case 0xA1:
            return 0x00;
        case 0xA2:
            return 0x00;
        case 0xA3:
            return 0x00;
        case 0xA4:
            return 0x00;
        case 0xA5:
            return 0x00;
        case 0xA6:
            return 0x00;
        case 0xA7:
            return 0x00;
        case 0xA8:
            return 0x00;
        case 0xA9:
            return 0x00;
        case 0xAA:
            return 0x00;
        case 0xAB:
            return 0x00;
        case 0xAC:
            return 0x00;
        case 0xAD:
            return 0x00;
        case 0xAE:
            return 0x00;
        case 0xAF:
            return 0x00;
        case 0xB0:
            return 0x00;
        case 0xB1:
            return 0x00;
        case 0xB2:
            return 0x00;
        case 0xB3:
            return 0x00;
        case 0xB4:
            return 0x00;
        case 0xB5:
            return 0x00;
        case 0xB6:
            return 0x00;
        case 0xB7:
            return 0x00;
        case 0xB8:
            return 0x00;
        case 0xB9:
            return 0x00;
        case 0xBA:
            return 0x00;
        case 0xBB:
            return 0x00;
        case 0xBC:
            return 0x00;
        case 0xBD:
            return 0x00;
        case 0xBE:
            return 0x00;
        case 0xBF:
            return 0x00;
        case 0xC0:
            return 0x00;
        case 0xC1:
            return 0x00;
        case 0xC2:
            return 0x00;
        case 0xC3:
            return 0x00;
        case 0xC4:
            return 0x00;
        case 0xC5:
            return 0x00;
        case 0xC6:
            return 0x00;
        case 0xC7:
            return 0x00;
        case 0xC8:
            return 0x00;
        case 0xC9:
            return 0x00;
        case 0xCA:
            return 0x00;
        case 0xCB:
            return 0x00;
        case 0xCC:
            return 0x00;
        case 0xCD:
            return 0x00;
        case 0xCE:
            return 0x00;
        case 0xCF:
            return 0x00;
        case 0xD0:
            return 0x00;
        case 0xD1:
            return 0x00;
        case 0xD2:
            return 0x00;
        case 0xD3:
            return 0x00;
        case 0xD4:
            return 0x00;
        case 0xD5:
            return 0x00;
        case 0xD6:
            return 0x00;
        case 0xD7:
            return 0x00;
        case 0xD8:
            return 0x00;
        case 0xD9:
            return 0x00;
        case 0xDA:
            return 0x00;
        case 0xDB:
            return 0x00;
        case 0xDC:
            return 0x00;
        case 0xDD:
            return 0x00;
        case 0xDE:
            return 0x00;
        case 0xDF:
            return 0x00;
        case 0xE0:
            return 0x00;
        case 0xE1:
            return 0x00;
        case 0xE2:
            return 0x00;
        case 0xE3:
            return 0x00;
        case 0xE4:
            return 0x00;
        case 0xE5:
            return 0x00;
        case 0xE6:
            return 0x00;
        case 0xE7:
            return 0x00;
        case 0xE8:
            return 0x00;
        case 0xE9:
            return 0x00;
        case 0xEA:
            return 0x00;
        case 0xEB:
            return 0x00;
        case 0xEC:
            return 0x00;
        case 0xED:
            return 0x00;
        case 0xEE:
            return 0x00;
        case 0xEF:
            return 0x00;
        case 0xF0:
			if(shiftcap == 0)
            	return '7';
			else
				return '&';
        case 0xF1:
            return 0x00;
        case 0xF2:
            return 0x00;
        case 0xF3:
            return 0x00;
        case 0xF4:
            return 0x00;
        case 0xF5:
            return 0x00;
        case 0xF6:
            return 0x00;
        case 0xF7:
            return 0x00;
        case 0xF8:
            return 0x00;
        case 0xF9:
            return 0x00;
        case 0xFA:
            return 0x00;
        case 0xFB:
            return 0x00;
        case 0xFC:
            return 0x00;
        case 0xFD:
            return 0x00;
        case 0xFE:
            return 0x00;
        case 0xFF:
            return 0x00;
	}
	return ' ';
}
/* ***********************************
LCD Stuff
************************************ */
void LCDString(rom unsigned char *str){
	while(*str != 0)
		SendLCD(*str++,1);
}
void InitLCD(void){
	LCDt = 0x00;
	RS = 0;
	Delay10KTCYx(4);	//Delay 40000 TCY aka 20mS

	LCD = 0x03;
	ToggleE();
	Delay10KTCYx(1);	//Delay 10000 TCY aka 5mS

	ToggleE();
	Delay10KTCYx(1);	//Delay 10000 TCY aka 5mS

	ToggleE();
	Delay10KTCYx(1);	//Delay 10000 TCY aka 5mS
	Delay1KTCYx(2);		//Delay 2000 TCY aka 1mS  // Total = 6mS

	LCD = 0x02;
	ToggleE();
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS

	SendLCD(0x28,0);	//Data = 0x28, RS = 0 (command mode)
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS

	SendLCD(0x10,0);	//Data = 0x10, RS = 0 (command mode)
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS

	SendLCD(0x06,0);	//Data = 0x06, RS = 0 (command mode)
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS

	SendLCD(0x0F,0);	//Data = 0x0F, RS = 0 (command mode)
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS

	SendLCD(0x01,0);	//Data = 0x01, RS = 0 (command mode)
	Delay1KTCYx(8);		//Delay 8000 TCY aka 4mS
}
void LCDLine(unsigned char line){
	if(line == 1)
		SendLCD(0x80,0);

	if(line == 2)
		SendLCD(0xC0,0);
}
void SendLCD(unsigned char dat,unsigned char RSV){
	char cmdHi;
	char cmdLo;

	cmdHi = dat >> 4;
	cmdLo = dat & 0x0F;

	LCD = cmdHi;
	RS = RSV;
	ToggleE();

	Delay10TCYx(2); 		//10uS Delay

	LCD = cmdLo;
	RS = RSV;
	ToggleE();
}
void ToggleE(void){
	ET = 1;
	Delay10TCYx(2); 		//10uS Delay
	ET = 0;
}

All Alphabets and Shift/Alphabets work and Numbers and SHIFT/Numbers. and space.

Enter Key should return a LF. You can alter it to what ever you want. Tab returns a HT.
 
Last edited:
Nice job Jason. This is a great example of why this forum rocks! Somebody works hard and figures most of it out on their own then a experienced software/hardware EE comes along and makes suggestions for improvements. I'm still in the basic part of PIC's (not completely through Nigel's tutorials) but this is inspiring. Maybe i'll get there someday.

Thanks for posting your work... looks great.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top