/ ************************************************* ***************************
* File: main.c
* function: a counter controlled by two buttons down counter, and the output digital display ..
************************************************** ************************** /
#include "config.h"
#include "math.h"
#define CON 0x00ffffff // control P0. 0 ~ P0.23 as an output pin
#define SWl (30 <<. 1)
#define SW2 0x80000000
/ ************************************************* ***************************
* name: DelayNS ()
*: long software delay
* entrance parameters: delay DLY parameter value the larger, longer delay
* export parameters: None
*************************************** ************************************* /
void delay(uint32 dly)
{
uint32 i;
for(; dly>0; dly--)
for(i=0; i<250; i++);
}
void clear_All () // off the lights in both directions, LED is cleared
{
to IO0CLR = CON;
// returns high until the switch SW2, start working again
the while (. 1)
{
IF ((the IO0PIN & SW2) = = SW2) // =. 1 If P0.31
{
BREAK;
}
}
}
void yellow_Light () // night mode
{
The PINSEL0 = 0; // P0.0-15 to the GPIO
The PINSEL1 = 0; // P0.16-31 to the GPIO
IO0DIR = CON;
to IO0CLR = CON;
the while (. 1)
{
IF ( (IO0PIN & SW1) == SW1) // =. 1 If P0.30
{
BREAK;
}
the else if ((& SWl the IO0PIN) == 0) // if 0 = P0.30
{
// switch SW2 monitoring points
if ( (IO0PIN & SW2) == 0) // if P0.31 = 0, the system shutdown signal
{
clear_All ();
}
//P0.17, high-low transition P0.20
IO0SET = 0x120000;
Delay (1000);
to IO0CLR = 0x120000;
delay(1000);
}
}
}
main int ()
{
int temp1;
int In Flag; // distinguish first lamp is red or green light, red light represents, represents green
int judge; // if other light yellow light, judge = 1, otherwise 0
// switch SW1 monitoring point
if ((IO0PIN & SW1) == 0) // if P0.30 = 0, into the night mode
{
yellow_Light ();
}
// switch SW2 monitoring point
if ((IO0PIN & SW2) = = 0) // if P0.31 = 0, the system shutdown signal
{
clear_All ();
GOTO the Start;
}
the Start:
temp1 = 15;
In Flag =. 1;
Judge = 0;
The PINSEL0 = 0; // to P0.0-15 the GPIO
The PINSEL1 = 0; // P0.16-31 to the GPIO
IO0DIR = CON;
to IO0CLR = CON;
// at the start of the red light, is set P0.16 = 1
// green light in the other direction, is set. 1 = P0.21
IO0SET = 0x210000;
the while (. 1)
{
to IO0CLR = 0xFFFF;
IO0SET = 16 * (temp1 / 10) + 10% temp1;
IF (Judge In Flag == =. 1 && = 0) // red cycle, another cycle of the signal is green
{
IO0SET = (16 * ((temp1 -. 3) / 10) + (temp1 -. 3) 10%) * POW (16,2);
}
the else IF (flag == 2) // green period, the other signal is a light cycle
{
IO0SET = (16 * ((+ temp1. 3) / 10) + (+ temp1. 3) 10%) * POW (16,2);
}
IF (temp1 <&& In Flag ==. 3. 1) // last three seconds of red
{
// the other direction the yellow light green P0.20 = 1 + 0 = off P0.21
Judge =. 1;
IO0SET = 0x100000; // yellow light in the other direction P0.20 = 1
IO0CLR = 0x200000; // the other direction the green light off = 0 P0.21
IO0SET = (16 * (temp1 / 10) temp1 + 10%) * POW (16,2); // other direction countdown yellow
}
temp1- -;
Delay (500);
IF (temp1 <2 && In Flag == 2) // 02 01 00s green flashing
{
to IO0CLR = 0x40000; // green light off, P0.18 = 0
}
IF (temp1 <&& In Flag ==. 5 1 && judge == 0) // last three seconds of a further green signal
{
to IO0CLR = 0x200000; // green light off in another direction, P0.21 = 0
}
Delay (500);
IF (temp1 <2 && In Flag == 2 ) // 020 100 flashing green
{
IO0SET = 0x40000; // green light, P0.18 =. 1
}
IF (temp1 <. 1. 5 & && In Flag ==& Judge == 0) // green signal further last 3 seconds
{
IO0SET = 0x200000; // green light in the other direction, P0.21 =. 1
}
// switch SW1 monitoring point
if ((IO0PIN & SW1) == 0) // if P0.30 = 0, into the night mode
{
yellow_Light ();
GOTO the Start; // switch SW1 to be raised, the end of the night mode, re day mode enters
}
// switch SW2 monitoring point
if ((IO0PIN & SW2) == 0) // if P0.31 = 0, the system shutdown signal
{
clear_All ();
GOTO the Start;
}
IF (temp1 == -1)
{
IF (In Flag ==. 1) end of the light cycle //
{
In Flag = 2; // green period is about to enter identification
IO0CLR = 0x110000; // red light off, P0.16 0 = other direction indicator is off P0.20 0 =
IO0SET = 0xC0000; // becomes light green, P0.18 = 1 in the other direction becomes red P0.19 = 1
judge = 0; // yellow period ends in the other direction
temp1 = 11; // green 11S
}
the else IF (In Flag == 2) // End cycle green
{
In Flag =. 1; // identification threshold of the light cycle
IO0CLR = 0x40000; // green light off, P0.18 = 0
temp1 = 2; // yellow cycle 2S
IO0SET = 0x20000; // yellow light, P0.17. 1 =
the while (temp1> = 0) // yellow period
{
// switch SW1 monitoring point
if ((IO0PIN & SW1) == 0) // if P0.30 = 0, into the night mode
{
yellow_Light ();
GOTO the Start; // switch SW1 to be raised, the end of the night mode, mode re-enter the day
}
// switch SW2 monitoring point
if (( IO0PIN & SW2) == 0) // if P0.31 = 0, the system shutdown signal
{
clear_All ();
GOTO the Start;
}
to IO0CLR = 0xFFFF; // Clear digital
IO0SET = 16 * (temp1 / 10 ) + temp1% 10; // yellow digital display period
IO0SET = (16 * (temp1 / 10) + temp1% 10) * pow (16,2); // another signal light cycle 020 100 digital display
Delay (1000);
temp1 -;
}
to IO0CLR = 0x20000; // indicator is off, P0.17 = 0
IO0SET = 0x210000; // light becomes red, P0.16 = 1 in the other direction becomes green. 1 = P0.21
to IO0CLR = 0x80000; = 0 // red light off P0.19
temp1 = 15; // red 15s
}
}
}
}