//---------------------------------------------------------------------------------
//
// Main Project : Keyboard and LCD
// C2C Proyect Name : Keyblcd
// File Name : keyblcd.c
// Version : 1.0
// PIC Used : PIC16F84A
// Compiler version : C2C plus C-Compiler Version 4.00.7 English
// Asembler : mpasmwin From MPLAB 5.70.00, Microchip Technology, Inc.
// Initial Date : Decembar 15 2002
// Last Update date : Febrary 16 2002
// Firmware Eng. : Julio Cesar Silva Briano
// Desing Eng. : Julio Cesar Silva Briano
//
//---------------------------------------------------------------------------------
//
// Based Document:
//
// 1) File Name :
// 2) File Name : Data sheet : F84A Data sheet - 35007b.pdf
// 3) File Name : C2C help index.pdf
//
// Note :
//
//---------------------------------------------------------------------------------
//
// Description of this C code:
//
// This routine continually executes this main rutines
//
// 1) Control LCD 16x2
// 2) Keyboard decoder
//
//--------------------------------------------------------------------------------
//
// Hardware Description:
//
// __________ _________
// PIN01-| PA.2 U PA.1 |-PIN18
// PIN02-| PA.3 PA.0 |-PIN17
// PIN03-| CLKin 1 OSC1 |-PIN16
// PIN04-| RST 6 OSC2 |-PIN15
// PIN05-| GND F VCC |-PIN14
// PIN06-| PB.0 8 PA.7 |-PIN13
// PIN07-| PB.1 4 PA.6 |-PIN12
// PIN08-| PB.2 A PA.5 |-PIN11
// PIN09-| PB.3 PA.4 |-PIN10
// ---------------------
//
//---------------------------------------------------------------------------------
//
// Used pines:
// PIN01 = LCD_DATA_6
// PIN02 = LCD_DATA_7
// PIN03 = DATA
// PIN04 = Not Used
// PIN05 = Ground
// PIN06 = CLOCK
// PIN07 = LCD_RS
// PIN08 = Not Used
// PIN09 = LCD_SEL
// PIN10 = Not Used
// PIN11 = Not Used
// PIN12 = Not Used
// PIN13 = Not Used
// PIN14 = VCC
// PIN15 = OSC2
// PIN16 = OSC1
// PIN17 = LCD_DATA_4
// PIN18 = LCD_DATA_5
//
//---------------------------------------------------------------------------------
//
// Hardware NOTES:
// Defalut OSC 4MHZ
//
//---------------------------------------------------------------------------------
asm __config 0x3FF9 ;//CODE FOR 16F84A ONLY!!
//-------------------
// INCLUDE SECTION
//-------------------
#include "LCDTest.c"
#include "keyblcd.h"
#include "scancod.h"
//----------------------------------------------------------
// Function Name : void main(void)
// Description : Main block
// Local Variables : NONE
// Return Value : NONE
//----------------------------------------------------------
void main(void)
{
//-----------------
// Main block
//-----------------
set_bit( STATUS, RP0 );
OPTION_REG = CFG_OPTION; //Configure the OPTION register
set_tris_a( PortAConfig); // PORT A Setup
set_tris_b( PortBConfig ); // PORT B Setup
clear_bit( STATUS, RP0 );
output_low_port_a( LCD_SEL ); // Disable LCD
//Configure the INTCON register
INTCON = CFG_INTCON;
// Setup the LCD device
LCD_Setup();
//disable TMR0
clear_bit(INTCON,5);
//disable INT
clear_bit(INTCON,4);
//-----------------
// Initialization
//-----------------
intc=0;
indexBuffer=0;
newByte=0;
counter3=0;
LCD_FunctionMode();
LCD_Write_4_Bit(set_dd_line1);
LCD_DataMode();
WriteLCDString( " keyboard " );
texto[0] = ' ';
texto[1] = ' ';
texto[2] = ' ';
texto[3] = ' ';
texto[4] = ' ';
texto[5] = ' ';
texto[6] = ' ';
texto[7] = ' ';
texto[8] = ' ';
texto[9] = ' ';
texto[10] = ' ';
texto[11] = ' ';
texto[12] = ' ';
texto[13] = ' ';
texto[14] = ' ';
texto[15] = ' ';
//enable INT
set_bit(INTCON,4);
//-------------------------------
// Main Loop
//-------------------------------
for(;;)
{
//Wait new byte
if (newByte)
{
newByte=0;
//decode the key
decode();
//the second code is the real key
if (charCounter==2)
{
charCounter=0;
indexBuffer++;
texto[indexBuffer] = realKey;
if (indexBuffer==15)
indexBuffer=0;
}
}
//display chacarter
LCD_FunctionMode();
LCD_Write_4_Bit(set_dd_line2); // Goto line 2
LCD_DataMode();
WriteVaribleString();
}
}
//--------------------------------------------------------------------
// Function Name : void inteHandler( void )
// Description : Detect the clock pulse for new bit
// Local Variables : NONE
// Return Value : NONE
//--------------------------------------------------------------------
void inteHandler( void )
{
pinIn=input_pin_port_a(4);
intc++;
switch (intc)
{
case START:
if (pinIn || input_pin_port_b(0))
{
intc=0;
}
keyIn=0;
statusParity=0;
break;
case PARITY:
statusParity = pinIn;
break;
case STOP:
newByte = 1;
intc=0;
break;
default:
keyIn = keyIn >> 1;
if (pinIn)
{
keyIn = keyIn | 0x80;
}
break;
}
}
//--------------------------------------------------------------------
// Function Name : void interrupt( void )
// Description : general interrupt handler
// Local Variables : NONE
// Return Value : NONE
//--------------------------------------------------------------------
void interrupt( void )
{
//RB0/INT Interrupt processing
if( INTCON & 2 )
{
clear_bit( INTCON, 1 );
inteHandler();
}
}
//----------------------------------------------------------
// Function Name : void decode(void)
// Description : decode stroke key
// Local Variables : NONE
// Return Value : NONE
//----------------------------------------------------------
void decode(void)
{
char i,indice;
charCounter++;
switch (keyIn) //scan code
{
case 0xF0: //The up-key idientifier
isUp=1;
shift=0;
break;
case 0x12: //Left SHIFT
charCounter=1;
shift=1;
break;
case 0x59: //Righ SHIFT
charCounter=1;
shift=1;
break;
case 0x05: // F1
shift=0;
break;
default :
if (!shift) //If shift not pressed
{
for (i=0;i<=67;i++)
{
if (index[i]==keyIn)
{
realKey=unshifted[i];
}
}
}
else
{
for (i=0;i<=67;i++)
{
if (index[i]==keyIn)
{
realKey=shifted[i];
}
}
}
shift=0;
break;
}
}
Copyright © 2002-2006 SourceBoost Technologies