beeson76
Newbie
I would like to make a simple embedded program that will Display what is happening on and LCD screen. When Switch One is pressed, it displays "Switch One". When Switch 2 is pressed it displays Switch 2 so on. For Switches 7 and 8 I would like to have a diode in Circuit as you can see from the Schematic.
As you can see from the schematic I have 2 Diodes on Switch 7 and 2 Diodes on Switch 8. IF I reverse the Diodes the program runs correctly and when Switches 7 and 8 are pressed they are Displayed correctly on the Display. I would like to have the Diodes reversed though. So I somehow need to reverse the way the Pins are reading from Input to Output...or from High to Low or vice versa. My concept of Inputs, Outputs, Highs, and Lows, are not quite up to par yet Any help is greatly appreciated!!
Here is the code in which runs perfectly IF the Diodes are reversed. It may not be able to even be done. I have spent hours trying to get this to work and I am now at a loss as to what I need to do. My brain is fried!!
Thanks again for any help you guys!!
As you can see from the schematic I have 2 Diodes on Switch 7 and 2 Diodes on Switch 8. IF I reverse the Diodes the program runs correctly and when Switches 7 and 8 are pressed they are Displayed correctly on the Display. I would like to have the Diodes reversed though. So I somehow need to reverse the way the Pins are reading from Input to Output...or from High to Low or vice versa. My concept of Inputs, Outputs, Highs, and Lows, are not quite up to par yet Any help is greatly appreciated!!
Here is the code in which runs perfectly IF the Diodes are reversed. It may not be able to even be done. I have spent hours trying to get this to work and I am now at a loss as to what I need to do. My brain is fried!!
Thanks again for any help you guys!!
Code:
#define _LEGACY_HEADERS
#include <htc.h>
#include "lcd.h"
////
////DEFINE STATEMENTS
////
#define SWITCH1 RB0
#define SWITCH2 RB1
#define SWITCH3 RB2
#define SWITCH4 RB3
#define SWITCH5 RB4
#define SWITCH6 RB5
#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
////
////
////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 (MCLRDIS & 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) (0xFF 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 ........
ADCON0 = 0;
ADCON1 = 0;
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; //
//The following Code will Display the name of the tester and the Rev. only once for a total of
//2 seconds. This happens right when you turn it on. I had to keep it out of the while statement
//because it keeps cycling over and over again. Therefore it had to be before that. After the
//Name and Rev. is displayed for 2 seconds, we have to clear the LCD of the Name and Rev.. Therefore
//the use of lcd_clear is required to clear the screen.
lcd_goto(0); //
lcd_puts("SWITCH_TESTER"); //
lcd_goto(40); //
lcd_puts("Rev. 0.0"); //
__delay_ms(2000); //Display Name and Rev. for 2000 ms (2 seconds)
lcd_clear(); //The Screen is cleared of Name and Rev.
while (1)
{
lcd_goto(0); //Go to Line 1 Position 1
lcd_puts("SWITCH Tester"); //Display ""
lcd_goto(40); //Go to Line 2 Position 1
lcd_puts("Press SWITCH"); //Display "Press SWITCH"
b = 0;
while ((SWITCH1 == 0) && (SWITCH5 == 1)) //While SW1 is 0(Low)(Pressed)...
{
__delay_ms(10); //Delay 10 ms (Switch Debounce)
while ((SWITCH1 == 0) && (SWITCH5 == 1)) //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("SWITCH 1"); //Display ""
b = 1; //Char B is now 1 so For Statement cycles once
}
}
while ((SWITCH2 == 0) && (SWITCH6 == 1))
{
__delay_ms(10);
while ((SWITCH2 == 0) && (SWITCH6 == 1))
{
for (a = b; a < 1; a++)
{
lcd_clear();
}
lcd_goto(0);
lcd_puts("SWITCH 2");
b = 1;
}
}
while ((SWITCH5 == 0) && (SWITCH1 == 1))
{
__delay_ms(10);
while ((SWITCH5 == 0) && (SWITCH1 == 1))
{
for (a = b; a < 1; a++)
{
lcd_clear();
}
lcd_goto(0);
lcd_puts("SWITCH 5");
b = 1;
}
}
while ((SWITCH6 == 0) && (SWITCH2 == 1))
{
__delay_ms(10);
while ((SWITCH6 == 0) && (SWITCH2 == 1))
{
for (a = b; a < 1; a++)
{
lcd_clear();
}
lcd_goto(0);
lcd_puts("SWITCH 6");
b = 1;
}
}
while (SWITCH3 == 0)
{
__delay_ms(10);
while (SWITCH3 == 0)
{
for (a = b; a < 1; a++)
{
lcd_clear();
}
lcd_goto(0);
lcd_puts("SWITCH 3");
b = 1;
}
}
while (SWITCH4 == 0)
{ //...
__delay_ms(10); //
while (SWITCH4 == 0) //
{ //
for (a = b; a < 1; a++) //
{ //
lcd_clear(); //...
} //...
lcd_goto(0); //...
lcd_puts("SWITCH 4"); //Display ""
b = 1; //
} //
} //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Tried changing PortB to High by using
//PORTB - 0xFF;
//Input by using
//TRISB = 0xFF;
//
//I am sure code codes goes here for Switchs 7 and 8
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
while ((SWITCH1 == 0) && (SWITCH5 == 0))
{ //...
__delay_ms(10); //
while ((SWITCH1 == 0) && (SWITCH5 == 0))
{ //
for (a = b; a < 1; a++) //
{ //
lcd_clear(); //...
} //...
lcd_goto(0); //...
lcd_puts("SWITCH 7"); //Display "SW7"
b = 1; //
}
} //
//
while ((SWITCH2 == 0) && (SWITCH6 == 0)) //
{ //...
__delay_ms(10); //
while ((SWITCH2 == 0) && (SWITCH6 == 0))
{ //
for (a = b; a < 1; a++) //
{ //
lcd_clear(); //...
} //...
lcd_goto(0); //...
lcd_puts("SWITCH 8"); //Display ""
b = 1; //
}
}
}
}