About interrupts?
I am coding for a basic traffic light control to be displayed on the monitor.
In what I need for an external interrupt (event) to occur and the state of the current traffic light to change. I am trying to do this without any board or external peripherals.
Now I think I have the following options. tell me which is better.
1. One interrupt function to be installed on the system that will interrupt periodically? (But I don't know how to install this ... any body please help me on this)
2. AC running on a second PC or hyperterminal, which will regularly send several different values with a delay to the serial port of the PC running the traffic light program, which will regularly check this value, and for one set of data it will change by one state and for another dataset, a different state. Thus, the two programs will run simultaneously on their own system.
3. Or do you still need to use an external interrupt generator?
In the above methods, this is the best way to do it. or is there another alternative that is simpler and does not include external hardware. If any of the above solutions are wrong, please ignore them. My environment is turbo C on windows (gcc answers are also invited by bcos, I have TRITON IDE with gcc installed on windows for ARM7)
source to share
You can just do a multi-threaded application and have some protective actions like interrupts when it wakes up.
Insert one: Traffic control Thread two: Simulate traffic coming from the east requiring league changes and randomly sleeping 1 to 60 seconds before waking up again. Theme X uses imagination.
In gcc, this can be done easily if you have the pthread lib for one example.
source to share
Option 1 is the simplest, you just create a timer that will interrupt your program at regular intervals. You say you are programming in C but do not specify the platform, timers are platform dependent.
On Unixland, timers send signals to be processed upon completion. In particular, the timer implementation for Linux is setitimer .
Then you need to catch and process the signals sent by the timer.
You can also use timers in the Win32 API , but the concept is slightly different.
source to share
Get a copy of the Microsoft® Win32® Programmer's Guide : Win32.hlp
Look for SetTimer and related functions. This function registers on windows that you want to call the function at a specified interval (from the time setTimer was called). My suggestion is that on this function you: - kill this timer and set another one the same as it (ie the same interval, the same function); - increase the counter; - check the counter for constants;
those. Counter = 10, change to yellow, = 20, to green, 30 to red and reset.
If the idea is for the traffic light to react to something else, replace the counter logic with something else.
The main () of your program is just your timer initialization and some time (1). The rest is done by the timer function.
source to share