📄 rgb_led.c
字号:
//include file
#include <pic.h>
//16F84 configuration
__CONFIG(0x3FF1);
//portb macro
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
//portb pin assignment
static bit LED0 @ PORTBIT(PORTB, 0);
static bit LED1 @ PORTBIT(PORTB, 1);
static bit LED2 @ PORTBIT(PORTB, 2);
static bit LED3 @ PORTBIT(PORTB, 3);
static bit LED4 @ PORTBIT(PORTB, 4);
static bit LED5 @ PORTBIT(PORTB, 5);
static bit LED6 @ PORTBIT(PORTB, 6);
static bit LED7 @ PORTBIT(PORTB, 7);
//global variables
unsigned int i; //for loop pause
unsigned int c; //for loop event loop
//functions
void pause_action(); //pause
void blink_redgreen(); //blink red then green
void blink_baf(); //blink red and green back and forth
void alt_blink(); //every other red then green
void blink_sequence(); //blinks red one at a time
//end functions
//main function
void main(void)
{
TRISB = 0x00;
PORTB = 0b00000000;
while(1)
{
blink_redgreen();
blink_baf();
alt_blink();
blink_sequence();
};
}
//end main function
void pause_action()
{
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
};
void blink_redgreen()
{
for(c=0; c<10; c++)
{
PORTB = 0b10101010;
pause_action();
PORTB = 0b01010101;
pause_action();
};
};
void blink_baf()
{
for(c=0; c<10; c++)
{
PORTB = 0b10100101;
pause_action();
PORTB = 0b01011010;
pause_action();
};
};
void alt_blink()
{
for(c=0; c<10; c++)
{
PORTB = 0b10011001;
pause_action();
PORTB = 0b01100110;
pause_action();
};
};
void blink_sequence()
{
for(c=0; c<10; c++)
{
PORTB = 0b10010101;
pause_action();
PORTB = 0b01100101;
pause_action();
PORTB = 0b01011001;
pause_action();
PORTB = 0b01010110;
pause_action();
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -