Just some tips on the PIC and LCD

Thread Starter

beeson76

Joined Apr 19, 2010
204
I have a LCD connected to a PIC16F886 along with 13 switches to the "remaining" pins for the PIC

Here is the layout

I am using PORTA0, 1, 3 of my PIC16F886 for the control lines to my LCD.

I am using PORTC0-3 for my data lines for my LCD

I have 13 switches all tied to the PIC using all of PORTB and the remaining 4 pins on PORTC.

Then I am using 1 pin on PORTA for the remaining 13th switch.

I know this question is vague, but can anyone see a problem with this scenario? Such as pins being set up right etc.

I have it in the program as the the pins being pulled low (RB0 == 0) for example.

I have to use a PIC with 28 pins because the only programmer I have is only 28 pins. And the only chip I have access to right now is the PIC16F886. So I so really prefer to stay with this arrangement if possible.

I will try to post the program tomorrow with schematic. I was just wanting to start a post to get some answers if possible.

Thanks for any help provided. I love this forum:)
 

MMcLaren

Joined Feb 14, 2010
842
Have you considered multiplexing the switches with the LCD D4..D7 lines? If you were to use those lines as switch matrix column driver lines you would only need another four I/O pins (and diodes) to read up to 16 switches in a 4x4 matrix configuration. That would reduce your I/O pin requirements from 20 pins (13+7) to 11 pins (4+7).

Regards, Mike
 

Eric007

Joined Aug 5, 2011
1,154
I think multiplexing is a better way to implement your hardware...

I have to use a PIC with 28 pins because the only programmer I have is only 28 pins.
Excuse me! I don't really get what you mean by that!! The programmer you have is only 28 pins???? Can you please explain...you mean your chip Not your programmer, right?

Regards
 

t06afre

Joined May 11, 2009
5,934
This will depend on what kind of programmer you have also. The important thing is not the number pins. But if the programmer software support the chip or not.
 

Thread Starter

beeson76

Joined Apr 19, 2010
204
Thanks for the replies.

I use the PicKit 2 as my programmer for my chips. I only have the development boards for the 28 pin and the 20 pin. I knew the 20 pin was too few so I am going with the 28 pin. And the only 28 pin chip I have right now is the PIC16F886.

I have messed around with matrix switches a few months ago, and the idea is pretty neat. But for this project, I want to use this switch (schematic is provided).

Im am still very new at this stuff. Mainly a hobby to see what I can do. So I appreciate your replies very much. I am having a lot of fun with it, and I am learning a lot too.

So with this switch, I don't see any way of putting it into a matrix type switch. Any help and suggestions is greatly appreciated.

Thanks again.
 

Attachments

BMorse

Joined Sep 26, 2009
2,675
Thanks for the replies.

I use the PicKit 2 as my programmer for my chips.
A pickit 2 programmer supports all sorts of Microchip uC's..... it is all in the way you connect the ICSP pins of the uC (If capable of In Circuit Serial Programming anyway...) So you are not limited to using those particular uC's as you can program any uC capable of ICSP...
 

t06afre

Joined May 11, 2009
5,934

ErnieM

Joined Apr 24, 2011
8,040
Hush up guys, his breadboarding platform is the expansion board, and as it has (albeit small) prototyping area is does have a place to stick down parts and try things. It's a good thing to start with known working hardware.

beesons: Your basic scheme seems OK. Just to start yourself off in a good place only add the LCD and get that to display something ("Hello World" is traditional). You are going to spend some time just getting that to work (we all did).

Then you can start adding some buttons to make it do something useful. Don't get into multiplexed buttons yet, make something simple work, just a couple of buttons maybe, so you learn all the gotcha's about adding buttons (like pull up or down resistors, debouncing, contact clearing...).

Make small steps so each one builds on the previous step.
 

ErnieM

Joined Apr 24, 2011
8,040
beeson: also MAKE THAT SCHEMATIC. It has to be the first step, even for simple things, so you know what you're doing and will still know when you have to stop for a day or a month.
 

MMcLaren

Joined Feb 14, 2010
842
beeson,

Did that bank of switches come wired that way or did you wire it that way?

BTW, I agree with Ernie. Take your time and do it one step at a time. Some newcomers try to do too all at once, often skipping important steps and research.

Mike
 

Thread Starter

beeson76

Joined Apr 19, 2010
204
Thanks everyone for the replies.

Here is the schematic for the switch and PIC and LCD.

The switches came that way. I have also gotten the LCD wired up with the "Hello World" being displayed right now:) It was kinda nice seeing that because usually it takes me a while to get to this point. So the LCD is being inialized etc.

A while ago, I tried putting all the data and control lines on one PORT and I couldnt get it done. It just didnt click with me moving the upper and lower bits around. That is why I have them on 2 different PORTS right now. I think that may be a problem though on PORTC.

Any thoughts and help is appreciated very much.

Thanks.
 

Attachments

Thread Starter

beeson76

Joined Apr 19, 2010
204
Here is the main code for the program

Rich (BB code):
//
//Programmed into this program is a debounce of 10 ms.  It is a very simple debounce statement.  It mainly consists of
//a while statement with a debounce statement followed by another while statement.  The first while statement test to see
//if a button is pressed.  If a button is pressed, a pause of 10ms is done, followed by another check of the button press.
//If the button is stilled pressed, the while loop continues.  If the button is not pressed, the while loop is broken 
//and it jumps back to the next while loop and tests again.  Therefore the debounce in this program is 10ms.
//
//Please noticed commented out lines.  There may be some left in, so further development can take place.  Further development 
//may consists of ideas or thoughts that are not yet programmed.  There may also still be left in this program some statements 
//that simply don't do anything.  This is also left in so further development may take place.


#define _LEGACY_HEADERS
#include <htc.h>
#include "lcd.h"

//DEFINE STATEMENTS
#define SW1			RC4
#define	SW2			RC5
#define	SW3			RC6
#define SW4			RC7
#define	SW5			RB0
#define	SW6			RB1
#define SW7			RB2
#define SW8			RB3
#define SW9			RB4
#define SW10		RB5
#define SW11		RB6
#define SW12		RB7

#define DelayS(T)		{unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}	//Delay Macro
#define _XTAL_FREQ				4000000								//Needs to be set for __delay_ms
//#define DEBOUNCE		10*1000/256									//Switch Debounce Count = 10ms/(256us/tick)
//#define DEBOUNCELOW(PIN)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////CONFIGURATION FUSES (BITS)
////Master Clear Reset enabled & Internal RC No Clock & Watchdog Timer Disable & Power Up Timer On & Brown Out Reset Disabled &
////Low Voltage Porgramming Disabled & Code Unprotect
__CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


main()
{
	
PORTA = 0x00;										//PORTA is cleared and set low
PORTB = 0xFF;										//(0b11111111 binary) (0xFF hex)--ROWS set to HIGH, COLUMNS set to HIGH  
													//PORTB7:B0 is set to high,high,high,high,high,high,high,high
													
//PORTC = 0x00;										//PORTC is cleared and set low
PORTC = 0xF0;										//PORTC is set to high, high, high, high, low, low, low, low
TRISA = 0x00;										//Set PORTA to outputs for LCD--RA1, RA2, RA4 are Control lines for LCD

TRISB = 0x7C;										//(0b01111100 binary) (0x7C hex)--ROWS set to INPUT, COLUMNS set to OUTPUT
													//PORTB7:B0 is set to output,input,input,input,input,input,output,output,
													//ROWS set to INPUT

//TRISC = 0x00;										//Set PORTC to outputs for LCD--RC0:RC3 are Data Lines for LCD
TRISC = 0xF0;										//Set PORTC to outputs for LCD--RC0:RC3 are Data Lines for LCD
													//Set PORTC to inputs for Pins RC4:RC7 for switch

ANSEL = 0;											//Initialize A/D Ports off
ANSELH = 0;											//Initialize ........
CM1CON0 = 0;										//Initialize Comparator 1 off
CM2CON0 = 0;										//Initialize Comparator 2 off

OPTION = 0b01010101;								//OPTION REG
													//xbxxxxx101  1:64
													//xbxxxx0xxx  Prescaler set to Timer0
													//xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
													//xbxx0xxxxx  (T0CS) Internal instruction cycle clock
													//xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
													//xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
RBPU = 0;											//Don't think I need this, but to be safe...PORTB Weak Internal Pullups enabled
WPUB0 = 0;											//COL_1 Weak pullup is individually DISABLED--OUTPUT 
WPUB1 = 0;											//COL_2 Weak Pullup is inidivdually DISABLED--OUTPUT
WPUB2 = 0;											//Not being used...Weak Pullup is individually DISABLED
WPUB3 = 1;											//ROW_1 Weak Pullup is individually ENABLED--INPUT
WPUB4 = 1;											//ROW_2 Weak Pullup is individually ENABLED--INPUT
WPUB5 =	1; 											//ROW_3 Weak Pullup is individually ENABLED--INPUT
WPUB6 = 1;											//ROW_4 Weak Pullup is individually ENABLED--INPUT
WPUB7 = 0;											//COL_3 Weak Pullup is individually DISABLED--INPUT


lcd_init();											//LCD Display is Initialized...See LCD.C file and LCD.h
lcd_clear();

char a;													//
char b;													//

while (1)
	{
		lcd_goto(0);									//Go to Line 1 Position 1
		lcd_puts("Hello");								//Display ""
		lcd_goto(40);									//Go to Line 2 Position 1
		lcd_puts("Press Button");						//Display "Press Button"
		b = 0;
		
		while (SW1 == 0)								//While SW1 is 0(Low)(Pressed)...
			{
				__delay_ms(10);							//Delay 10 ms (Switch Debounce)
				while (SW1 == 0)						//Check to see if SW1 is low after Debounce
					{
						for (a = b; a < 1; a++)			//For Statement to cycle lcd_clear only once
							{
								lcd_clear();			//lcd_clear should only cycle once because a = (b = 0)
							}
				
						lcd_goto(0);					//On LCD go to Position 1 (Line 1, Position 0)
						lcd_puts("SW1 Pressed");		//Display ""
						b = 1;							//Char B is now 1 so For Statement cycles once
					}
			}
		while (SW2 == 0)								//While ROW_2 is 0(Low)(Pressed)...
			{											//
				__delay_ms(10);							//
				while (SW2 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW2 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW3 == 0)								//While ROW_1 is 0(Low)(Pressed)...
			{											//
				__delay_ms(10);							//
				while (SW3 == 0)						//
					{									//...
						for (a = b; a < 1; a++)			//
							{							//	
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW3 Pressed");			//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW4 == 0)								//If ROW 4 is LOW
			{											//...
				__delay_ms(10);							//
				while (SW4 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW4 Pressed");			//Display ""
						b = 1;							//
					}									//	
			}											//
				
		while (SW5 == 0)								//and If ROW 1 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW5 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW5");				//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW6 == 0)								//if ROW 2 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW6 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW6 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW7 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW7 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW7 Pressed");		//Display "SW7"
						b = 1;							//
					}									//
			}											//
		while (SW8 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW8 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW8 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
				
		while (SW9 == 0)								//and If ROW 1 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW9 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW9 Pressed");		//
						b = 1;							//
					}									//
			}											//
		while (SW10 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW10 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW10 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW11 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW11 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW11 Pressed");		//Display ""
						b = 1;							//					
					}									//
			}											//
		while (SW12 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW12 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW12 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		
	}													//
}														//
 

BMorse

Joined Sep 26, 2009
2,675
You may want to add some 10k pullup resistors on your switch input lines, so you do not get any "ghost" inputs coming from the switches, this way the inputs stay High until a switch is pressed......
 

Thread Starter

beeson76

Joined Apr 19, 2010
204
Thanks BMorse. I will certainly look into the resistors and try to incorporate them into the circuit.

Also included is the lcd.c file

Rich (BB code):
/*
 *	LCD Interface Example
 *	This code will interface to a standard LCD controller
 *	like the Hitachi HD44780.  It uses it in 4 bit mode, with 
 *	the hardware connected as follows (the standard 14 pin
 *	LCD connector is used):
 *
 *	PORTC bits 0-3 are connected to LCD Data Bits 4-7 (High Nibble)
 *	PORTA bit 2 is connected to the LCD RS input (Register Select)
 *	RW input (Read/Write) is connected to Ground
 *	PORTA bit 1 is connected to the LCD EN bit (Enable)
*/

#include	<htc.h>
#include	"lcd.h"

void pause (unsigned short usvalue);			//Establish pause routine function

#define LCD_RS			RA2
#define LCD_RW			RA4
#define LCD_EN			RA1
#define LCD_DATA		PORTC
#define LCD_STROBE()	((LCD_EN = 1), (LCD_EN = 0))
#define  DelayS(T)				{unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}	//Delay Macro
#define  _XTAL_FREQ				4000000

/*Write a byte to the LCD in 4 bit mode*/

void
lcd_write(unsigned char c)
{
	__delay_ms(1);
	LCD_DATA = ((c >> 4) & 0x0F);
	LCD_STROBE();
	LCD_DATA = (c & 0x0F);
	LCD_STROBE();
}

/*Clear and Home the LCD*/

void
lcd_clear(void)
{
	LCD_RS = 0;
	lcd_write(0x1);
	__delay_ms(2);
}

/*Write a string of characters to the LCD*/

void
lcd_puts(const char * s)
{
	LCD_RS = 1;									//Write Characters
	while(*s)
	{
		lcd_write(*s++);
	}
}

/*Write one character to the LCD*/

void
lcd_putch(char c)
{
	LCD_RS = 1;									//Write Characters
	lcd_write(c);
}

/*Go to the Specified Position*/

void
lcd_goto(unsigned char pos)
{
	LCD_RS = 0;
	lcd_write(0x80 + pos);
}

/*Initialize the LCD - put into 4 bit mode*/

void
lcd_init()
{
	char init_value;
	
	ANSEL = 0;									//Disable Analog Pins on PORTA
	
	init_value = 0x3;
	TRISA = 0;
	TRISC = 0;
	LCD_RS = 0;
	LCD_EN = 0;
	LCD_RW = 0;
	
	__delay_ms(15);									//Wait 15ms after Power applies)
	LCD_DATA = init_value;
	LCD_STROBE();
	__delay_ms(10);
	LCD_STROBE();
	__delay_ms(10);
	LCD_STROBE();
	__delay_ms(10);
	LCD_DATA = 2;								//Four Bit Mode
	LCD_STROBE();
	
	lcd_write(0x28);							//Set Interface Length
	lcd_write(0xF);								//Display On, Cursor On, Cursor Blink
	lcd_clear();								//Clear Screen
	lcd_write(0x6);								//Set Entry Mode
}
The problem I am running into now is that since I am using PORTC for my data lines, its taking the full PORT to do it. (I believe anyway.::)) Is there anyway of differintiating (spelled that wrong) that I want to use the lower 4 pins instead of the whole port. And if I do that would that work with the set of code.

As I mentioned before I tried I didnt really understand the concept of upper and lower nibbles on that PORT from a while ago.

Thanks again for any help.
 

CraigHB

Joined Aug 12, 2011
127
You can work compeltely bitwise if you want so you don't have to consider ports as entities of 4 or 8 bits. There's a bunch of instructions that allow you to do things on a bit by bit basis. One of the main differences between micro-controllers and micro-processors is the ability to do this. Of course, coding parallel comms are easier when you can group things into a nibble or byte, but you don't have to do that.

I once coded an LCD display using 8 bit parallel comms without using a single group of bits, in other words, with some bits scattered in one register and some bits scattered in another register. I needed an LCD with very fast refresh on a small board so that's what I ended up with. Now I usually use serial comms for LCDs, but that was a long time ago when LCDs were slower. Display speeds have improved quite a bit since then.
 

ErnieM

Joined Apr 24, 2011
8,040
When I add the 10k pullup resistors they should be connected between the ground and the pin right?
That would be for a pull down resistor. A pull up resistor goes to Vdd.

However, the good news is that PIC already has pull ups built right into PortB where your switches are, all you have to do is turn them on.

Check Section 3.4.2 of your data sheet.
 
Last edited:

t06afre

Joined May 11, 2009
5,934
No pullups shall be connected to the same level as the microcontroller VDD. As you want to pull it up to a high level. Else it would have been named pulldown resistor.
 

CraigHB

Joined Aug 12, 2011
127
Typically, the switch connects to the low side with a pull-up between it and the high side. But, if you want to reverse the logic, you can connect the switch to the high side with a pull-down connecting the switch to the low side.

The more conventional way to do it is with a pull-up since it avoids putting direct supply voltage on the switch (more of a concern for higher voltage) and makes it easier to add debouncing and/or ESD protection.
 

Thread Starter

beeson76

Joined Apr 19, 2010
204
Here is my newest code. Pullup resisters are all working perfect by way of the built in resistors on PORTB.

To make things easier I switched 4 of my switches to PORTA. I am using PINS 0, 3, 5, 6 on PORTA now and my control lines are taking PINS 1, 2, 4.

But when I push a button, it flashes the switch name but then just locks up. I have pullups on all of those pins that have switches on them. It like its not clearing or something.

Rich (BB code):
#define _LEGACY_HEADERS
#include <htc.h>
#include "lcd.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////DEFINE STATEMENTS
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define SW1			RA0
#define	SW2			RA3
#define	SW3			RA5
#define SW4			RA6
#define	SW5			RB0
#define	SW6			RB1
#define SW7			RB2
#define SW8			RB3
#define SW9			RB4
#define SW10		RB5
#define SW11		RB6
#define SW12		RB7

#define DelayS(T)		{unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}	//Delay Macro
#define _XTAL_FREQ				4000000								//Needs to be set for __delay_ms
//#define DEBOUNCE		10*1000/256									//Switch Debounce Count = 10ms/(256us/tick)
//#define DEBOUNCELOW(PIN)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////CONFIGURATION FUSES (BITS)
////Master Clear Reset enabled & Internal RC No Clock & Watchdog Timer Disable & Power Up Timer On & Brown Out Reset Disabled &
////Low Voltage Porgramming Disabled & Code Unprotect
__CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


main()
{
PORTA = 0x00;										//PORTA is cleared	
PORTA = 0xE9;										//(ob11101001 binary) (0xE9 hex)
													//PORTA7:A0 is set to high,high,high,low,high,low,low,high
													
PORTB = 0x00;										//PORTB is cleared
PORTB = 0xFF;										//(0b11111111 binary) (0xFF hex)  
													//PORTB7:B0 is set to high,high,high,high,high,high,high,high
													
PORTC = 0x00;										//PORTC is cleared
PORTC = 0xF0;										//PORTC is set to high, high, high, high, low, low, low, low


TRISA = 0xE9;										//(0b11101001 binary)	(0xE9 hex)
													//LCD--RA1, RA2, RA4 are Control lines for LCD
													//RA0, RA3, RA5, RA6 are set for switches
													//PORTA7:A0 is set to input,input,input,output,input,output,output,input

TRISB = 0xFF;										//(0b11111111 binary) (0x7C hex)
													//All of PORTB are set for switches
													//PORTB7:B0 is set to input,input,input,input,input,input,input,input
												

TRISC = 0x00;										//(0b00000000 binary) (0x00 hex)
													//All of PORTC is set for LCD
													//PORTC7:C0 is set to output,output,output,output,output,output,output,output
													

ANSEL = 0;											//Initialize A/D Ports off
ANSELH = 0;											//Initialize ........
CM1CON0 = 0;										//Initialize Comparator 1 off
CM2CON0 = 0;										//Initialize Comparator 2 off

OPTION = 0b01010101;								//OPTION REG
													//xbxxxxx101  1:64
													//xbxxxx0xxx  Prescaler set to Timer0
													//xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
													//xbxx0xxxxx  (T0CS) Internal instruction cycle clock
													//xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
													//xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
RBPU = 0;											//Don't think I need this, but to be safe...PORTB Weak Internal Pullups enabled
WPUB0 = 1;											//COL_1 Weak pullup is individually ENABLED--INPUT 
WPUB1 = 1;											//COL_2 Weak Pullup is inidivdually ENABLED--INPUT
WPUB2 = 1;											//Not being used...Weak Pullup is individually ENABLED
WPUB3 = 1;											//ROW_1 Weak Pullup is individually ENABLED--INPUT
WPUB4 = 1;											//ROW_2 Weak Pullup is individually ENABLED--INPUT
WPUB5 =	1; 											//ROW_3 Weak Pullup is individually ENABLED--INPUT
WPUB6 = 1;											//ROW_4 Weak Pullup is individually ENABLED--INPUT
WPUB7 = 1;											//COL_3 Weak Pullup is individually ENABLED--INPUT


lcd_init();											//LCD Display is Initialized...See LCD.C file and LCD.h
lcd_clear();

char a;													//
char b;													//

while (1)
	{
		lcd_goto(0);									//Go to Line 1 Position 1
		lcd_puts("Hello");								//Display ""
		lcd_goto(40);									//Go to Line 2 Position 1
		lcd_puts("Press Button");						//Display "Press Button"
		b = 0;
		
		while (SW1 == 0)								//While SW1 is 0(Low)(Pressed)...
			{
				__delay_ms(10);							//Delay 10 ms (Switch Debounce)
				while (SW1 == 0)						//Check to see if SW1 is low after Debounce
					{
						for (a = b; a < 1; a++)			//For Statement to cycle lcd_clear only once
							{
								lcd_clear();			//lcd_clear should only cycle once because a = (b = 0)
							}
				
						lcd_goto(0);					//On LCD go to Position 1 (Line 1, Position 0)
						lcd_puts("SW1 Pressed");		//Display ""
						b = 1;							//Char B is now 1 so For Statement cycles once
					}
			}
		while (SW2 == 0)								//While ROW_2 is 0(Low)(Pressed)...
			{											//
				__delay_ms(10);							//
				while (SW2 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW2 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW3 == 0)								//While ROW_1 is 0(Low)(Pressed)...
			{											//
				__delay_ms(10);							//
				while (SW3 == 0)						//
					{									//...
						for (a = b; a < 1; a++)			//
							{							//	
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW3 Pressed");			//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW4 == 0)								//If ROW 4 is LOW
			{											//...
				__delay_ms(10);							//
				while (SW4 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW4 Pressed");			//Display ""
						b = 1;							//
					}									//	
			}											//
				
		while (SW5 == 0)								//and If ROW 1 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW5 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW5 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW6 == 0)								//if ROW 2 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW6 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW6 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW7 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW7 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW7 Pressed");		//Display "SW7"
						b = 1;							//
					}									//
			}											//
		while (SW8 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW8 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW8 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
				
		while (SW9 == 0)								//and If ROW 1 is LOW...
			{											//...
				__delay_ms(10);							//
				while (SW9 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW9 Pressed");		//
						b = 1;							//
					}									//
			}											//
		while (SW10 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW10 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...		
						lcd_goto(0);					//...
						lcd_puts("SW10 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		while (SW11 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW11 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW11 Pressed");		//Display ""
						b = 1;							//					
					}									//
			}											//
		while (SW12 == 0)								//
			{											//...
				__delay_ms(10);							//
				while (SW12 == 0)						//
					{									//
						for (a = b; a < 1; a++)			//
							{							//
								lcd_clear();			//...
							}							//...
						lcd_goto(0);					//...
						lcd_puts("SW12 Pressed");		//Display ""
						b = 1;							//
					}									//
			}											//
		
	}													//
}														//
 
Top