📄 t4_ledio.c
字号:
/*
** t4_ledio.c
*/
#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 );
/* LOCAL data */
static const unsigned char patterns[] =
{
/* OK kid, pick me up in the rear. */
0x01, 0x03, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xC0,
0x80, 0xC0, 0xE0, 0x70, 0x38, 0x1C, 0x0E, 0x07, 0x03
};
void main(void)
{
unsigned int i;
int j;
wsr = 0x1F;
set_led( 0 ); /* Clear the LEDs before enabling. */
enable_led();
while ( 1 )
for ( j = 0; j < sizeof( patterns); j++ )
{
set_led( patterns[j] );
wait_ms( 100 );
}
}
/* 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_1f;
}
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_1f;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -