📄 t2_ledio.c
字号:
/*
** t2_ledio.c
** Display some random patterns on the LEDs
** mixed with a slightly highlighted LED
** that runs from left to right.
*/
#include <stdio.h>
#include <stdlib.h>
#include _SFR_H_
/* IMPORT functions */
extern void wait_ms( int );
/* LOCAL functions */
static void enable_led( void );
static void set_led( unsigned char );
void main(void)
{
unsigned int i;
int j;
unsigned char mask;
set_led( 0 ); /* Clear the LEDs before enabling. */
enable_led();
for ( j = 0, mask = 0x01; ; j++ )
{
if ( (j % 64) == 0 )
{
mask = mask & 0x80 ? 0x01 : mask<<1;
}
i = rand();
set_led( i | mask );
wait_ms( 3 );
set_led( mask );
wait_ms( 7 );
}
}
/* LED I/O is connect to Port 1 */
static void enable_led( void )
{
/* Set all pins of port1 to open-drain output (external pull-up). */
asm stb 0,p1_dir;
}
static void set_led( register unsigned char b )
{
/* Each bit is a LED in the LED array. */
/* Note that there are ten LEDs,
one is unused,
one is for power-on indication. */
asm stb b,p1_reg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -