led.c
来自「《PIC单片机C语言开发入门》所有章节源程序」· C语言 代码 · 共 35 行
C
35 行
#include <pic.h>
/*
* Demo program
*
* Flashes LEDs on Port B, responds to switch press
* on RA1. Usable on PICDEM board.
*
* Copyright (C)1997 HI-TECH Software.
* Freely distributable.
*/
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
static bit button @ PORTBIT(PORTC, 1);
main(void)
{
unsigned char i, j;
TRISB = 0; /* all bits output */
j = 0;
for(;;) {
PORTB = 0x00; /* turn all on */
for(i = 100 ; --i ;)
continue;
PORTB = ~j; /* output value of j */
for(i = 100 ; --i ;)
continue;
if(button == 0) /* if switch pressed, increment */
j++;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?