I am really sorry if I am not understanding your questions. give me last chanceI am sorry. I really do not know where you are going with all of this.
Good luck.
what you want from me, flow chart , program or explanations?
I am really sorry if I am not understanding your questions. give me last chanceI am sorry. I really do not know where you are going with all of this.
Good luck.
Thanks a lot for helping me. I think its language problem. I was looking a old threads and I found this one https://forum.allaboutcircuits.com/...-and-loop-statements-in-c-programming.139161/You don't have to be sorry. But something is not connecting here. Is it the language differences?
It is late. I'll do some thinking on this.
Meanwhile, study this from another thread until it makes complete sense from start to finish.
It is a good example of a complete solution to a problem.
https://forum.allaboutcircuits.com/attachments/parthflowled-pdf.131934/
You should also go back to those older threads and read the parts on how to state a problem and construct a complete step-by-step process to solve it:
Decide what you want to do.
Express the problem in plain language.
Reduce the plain language to a step-by-step process that a computer can do.
Draw a flow chart that shows that step-by-step process.
Validate the process by tracing the flow for all conditions
When it works on paper, code it.
That is what has to happen.
#include<REGX51.h>
#define LED_ON (1)
#define LED_OFF (0)
#define Switch_Closed (1)
/*set bit P1^7 to LED*/
sbit LED = P1^7;
/*set bit P2^0 to Switch*/
sbit Switch = P2^0;
void main ()
{
Switch = Switch_Closed;
While (1)
{
LED = LED_OFF;
if (Switch == Switch_Closed)
{
LED = LED_ON;
}
else
{
LED = LED_OFF;
}
}
}
Feeling very sad for taking so much time to understand things. I have made new flow chart. there is little change in this flow charts. I have explain something, that I want to do with program. I am sure it will definitely work. so Please look at flow chart. does it match with Explanations ?Parth... you're not yet done with the flow chart that we got started with. I strongly suggest you finish it before jumping into writing code.
But it's important that you first learn how to express logic procedures in plain, clear language. That's what the flow charts are for.
Trust me when I tell you that that is a mistake, and it's not the best way to proceed.
You're almost there with the flowchart. Be patient and finish it, and then I'll be more than happy to help you with the code, step by step.
I will add another delay. you asked for logic so I am just explaining logic only. also I can draw flow chartBut what happens immediately after LED OFF? Remember that the computer is much faster than your eye. Do you think you will actually be able to see the LED off? Assuming that you want to see the LED flash on and off, what would you add to your logic?
Yes. I think that will fix it. Let's concentrate on this program for awhile. We'll do the others later.I will add another delay. you asked for logic so I am just explaining logic only. also I can draw flow chart
like this
do forever
LED ON
wait for some time
LED OFF
Wait for some time
Yes I know the program. we will make delay function and than we will call that function from main function.I don't have idea how to draw flow chart when we are calling to other function from main function. I can make flow chart for delay routine and main routine separately but how how to connect them when we are callingYes. I think that will fix it. Let's concentrate on this program for awhile. We'll do the others later.
Do you see anything that can be done with a sub-routine (also called a 'function' in C)?
In the main flow, just make a box that says Delay xxx mSec or Call Delay xxx mSec if you prefer. In this one, that box will appear twice yes?Yes I know the program. we will make delay function and than we will call that function from main function.I don't have idea how to draw flow chart when we are calling to other function from main function. I can make flow chart for delay routine and main routine separately but how how to connect them when we are calling
I made like thisIn the main flow, just make a box that says Delay xxx mSec or Call Delay xxx mSec if you prefer. In this one, that box will appear twice yes?
Next, make a separate flow chart for the Delay Subroutine - no arrows to or from main - it stands alone. If it is a fixed delay, name it Delay_100mS or whatever the delay is. If you want a variable delay, name it Delay_mSec (for example). The routine will take a passed-by-value parameter (the number of milliseconds to delay), delay that long then EXIT. Note that in a subroutine you CAN use EXIT in your flow chart since you are returning to main. When coding is C, try to have only one EXIT point, at the bottom of the flow chart.
So, two things to do:
Modify the main flow chart to call a delay subroutine
Write the delay subroutine using the same methods used to write main - describe it in plain language, flow chart it, run the flow chart mentally to detect any errors.
Keep at it, you are making progress.
ohh I forgot initialization step. First LED will set as High (LED ON). it will work like following programLooks pretty good! One thing you left out is the initialization step in main before the loop. All programs have to run some sort of init routine to set up the IO etc. before entering the main loop. What does this program need to init?
void delay (unsigned int j)
{
unsigned int j;
for (j = 0; j < 40000; j++);
{
}
}
void main()
{
LED = LED_ON
while (1)
{
LED = LED_ON;
delay(500);
LED = LED_OFF;
delay(1000);
}
}
I didn't write complete code. I just wanted to explain how delay routine work in programYou basically have it but there are a few bugs:
- You haven't defined 'LED' or LED_ON. The compiler needs to know those things.
- In delay, you pass in the parameter and call it 'j'. But then you declare another int and also call it 'j'. I expect what you are trying to do is just use the passed parameter to determine what the delay is. In that case, you don't need (or want) the second declaration. The compiler will make a copy of 'j' (passed by value), count using that copy then discard it when it returns from the function.
#include <REG51.h>
#define LED_ON (1) /* LED ON */
#define LED_OFF (0) /* LED OFF */
sbit LED = P1^7; /* LED connected to port P1 of pin 7 */
/* this is delay function */
void Delay (unsigned int Loop)
{
for (Loop = 0; Loop < 40000; Loop++);
{
}
}
void main()
{
LED = LED_ON; /* at start LED will should ON */
while (1)
{
LED = LED_ON; /* Turn ON LED */
Delay(500); /* Wait for some time */
LED = LED_OFF; /* turn off LED */
Delay(1000); /* Wait for some time */
}
}
You now have a good idea of how to get from idea to plain language statement of a problem, flow charting the solution, checking the flow chart and finally coding and testing. Let's be sure we go back and get the switch input stuff and any other left-overs working. Tag me in the thread that has the stuff we need to work on. When you have done a few more simple things, we can move on to LCD, keypads etc.I have already done work with LCD look at this thread https://forum.allaboutcircuits.com/threads/program-to-display-message-on-lcd.137686/
I have tested this code. code is working. also I have tested code with multiple messages.
I have done almost with switch,LED and LCD and I wanted to work with Keypad. but I was struggling with keypad interfacing. I have revisit many time on my threads I tried to understand the flow chart that you posted in thread but I didn't understand. still I am struggling with keypad interfacing
I think I have all done with switch and LED. And also I have tested code with LCD. I am facing problem only with keypad interfacing.You now have a good idea of how to get from idea to plain language statement of a problem, flow charting the solution, checking the flow chart and finally coding and testing. Let's be sure we go back and get the switch input stuff and any other left-overs working. Tag me in the thread that has the stuff we need to work on. When you have done a few more simple things, we can move on to LCD, keypads etc.
I don't have specific project in mind but so I will try to include all in one projectAm I correct that you eventually want to combine all of this stuff into one big project? If that is so, you should start working on the problem statement for that. Note that in big projects with lots of modules (LCD, keypad, switch inputs, LED indicators), it is helpful to use a BLOCK DIAGRAM as part of your problem statement that shows the individual modules and how they relate to each other.
Word of advice, aim for something simple at first, and then build on it after you've completed it. If you choose to do something useful, then so much the better. But make sure you completely finalize each stage before moving on with the next one. That way you'll stay motivated and more consistently grow in abilities and skills.I think I have all done with switch and LED. And also I have tested code with LCD. I am facing problem only with keypad interfacing.
https://forum.allaboutcircuits.com/threads/keypad-interfacing-using-8051.137828/
https://forum.allaboutcircuits.com/threads/how-to-display-number-on-lcd-through-user-input.138089/
https://forum.allaboutcircuits.com/threads/reading-data-from-device-in-programming.138302/
I started with matrix keypad but I couldn't complete it. than I started with switches but again failed.
I don't have specific project in mind but so I will try to include all in one project
For Example
Features of Project
1. Alarm clock that will show current time and date. and set Alarm for DC motor,
2. When Alarm will happen, buzzer will sound beep..
3. switch is use to Power On system,
4. LED will work as indicator to show the system is ON.
5. LCD to show date and time
6. I will add keypad for specific reason but at this I don't know whats purpose
I think it will cover all that I have learned here. I am just thinking I will be combine all of this stuff into one big project ?
Hardware Part lists
8051 MCU : At89c51
LCD display: 16x2
RTC: DS1307
Motor : DC Motor
Simple Keypad, Buzzer, LED, Switch
but at this time I am focusing on Keypad interfacing and RTC with I2C programming ?
No. I have done only with LCD. I wrote program for message display on screen using array and pointer. I wrote program to display multiple message on LCD. I have still problem with reading switch inputs. I want to understand reading switch input than go for keyboard scanning. I was reading old threads and looking flow chart.@Parth786
I share @cmartinez 's reservations on this one. Are you sure you have the LCD and reading switch inputs working and completely understood? .
we can continue with one example. I want to learn switch reading first than keypad reading and than I want to go for interrupts. I am reading some material and trying to make flow chart firstIf there are any remaining problems at all, those need to be cleaned up before going on to keyboard scanning. For example, we really didn't finish the original topic of this thread i.e. LED flashing under timer interrupt.
Are you pushing this to keep up with a school class and schedule? I am getting a little busy myself