Today learned a bit of the basics of single-chip microcomputer, wrote a simple LED running light program, to achieve 8 LEDs and so on from right to left cycle flashing.
Paste the code First:
#include <reg51.h>
#include <intrins.h>
void sleep (int t)
{
while (t--);
}
int main ()
{
int i;
P1 = 254;
while (1)
{for
(i = 7; I >= 0; i--)
{
sleep (z);
P1=_crol_ (p1,1);}}}
I use is a treasure above the study board, single-chip computer model is STC89C52.
At first I was prepared to use a sbit array to save 8 led addresses, and later found that 51 monolithic computer does not support bit arrays, the following query found this method.
The Reg51.h header file of the program defines the SRF P1 = 0x80, and I now understand that this initialization tells the address of the register P1, and then the operation of the P1 is the operation of this address memory (not quite the same as the usual OS-based initialization), then the following P1 = 254, is the P1 corresponding address of the eight-bit memory to 11111110 (for 0 o'clock corresponding LED light, this number of decimal is 254), and then use the _crol_ () function to achieve the P1 cycle left, so that 0 LED lights cycle change. The sleep () function implements the wait effect through multiple self-subtraction operations.