I am struggling with some basics. I think I am missing some basics. I think this is my third attempt to decrease the complexity of program on same topics.
I wrote this program to understand interfacing of LED and Switches. Now I am just trying to replace LED with LCD. so there are only switch and LCD connected to 8051. In program , if switch is High than LED should be ON and If switch is Low the LED should be OFF
I want to write c program for following conditions?
condition1 : if there is only one switch- read the condition of Switch if its ON than Display "1" on screen else don't display anything
Condition 2 : if there are two switches - read the condition of switches if SW1 on then Display "1" on screen and if if SW2 on then Display "2" on screen else don't display anything
generally I understand basics such as string, array, while loop, for loop, if else condition and I think I have to use these in program. I don't understand whats my fault why I am not making program. why I am not updating from LED to LCD so please help me on right direction
Code:
#include<REGX51.h>
#define LED_ON (1)
#define LED_OFF (0)
#define SW1_ON (1)
#define SW1_OFF (0)
#define SW2_ON (1)
#define SW2_OFF (0)
/*set bit P1^7 to LED*/
sbit LED = P1^7;
/*set bit P2^0 to Switch*/
sbit SW1 = P0^0;
sbit SW2 = P2^0;
void main ()
{
LED = LED_OFF;
while (1)
{
if (SW1 == 1 )
{
LED = LED_ON;
}
else
{
LED = LED_OFF;
}
}
I want to write c program for following conditions?
condition1 : if there is only one switch- read the condition of Switch if its ON than Display "1" on screen else don't display anything
Condition 2 : if there are two switches - read the condition of switches if SW1 on then Display "1" on screen and if if SW2 on then Display "2" on screen else don't display anything
generally I understand basics such as string, array, while loop, for loop, if else condition and I think I have to use these in program. I don't understand whats my fault why I am not making program. why I am not updating from LED to LCD so please help me on right direction
Last edited: