Led blinking
#include <htc.h> device dependent interrupt definitions
/*
* Works with MPLAB HITECH compiler
*
* pic 16f88
* need 10k on pin 4 to 5v to block reset
*
* Use 300 ohm resistors between LED and chip
*
* switches tris A and tris B high alternatively
*
*
*/
CONFIG(FOSC_INTOSCCLK);
Using Internal Clock of 8 Mhz
#define FOSC 8000000L
Delay Function
#define _delay_us(x) { unsigned char us; \
us = (x)/(12000000/FOSC)|1; \
while(--us != 0) continue; }
void main() {
TRISA = 0 ; set PORTA as OUTPUT
TRISB = 0 ; set PORTB as OUTPUT
TRISB = 0 ; set PORTB as OUTPUT
for(;;) forever
{
PORTB = 0xff ; turn all LEDs ON
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(1000);
PORTB = 0xff ; turn all LEDs ON
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(1000);
PORTB = 0x00 ; turn all LEDs OFF
PORTA = 0xff ; turn all LEDs ON
PORTA = 0xff ; turn all LEDs ON
_delay_us(1000);
PORTB = 0xff ; turn all LEDs ON
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(100);
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(100);
PORTB = 0x00 ; turn all LEDs OFF
PORTA = 0xff ; turn all LEDs ON
PORTA = 0xff ; turn all LEDs ON
_delay_us(100);
PORTB = 0xff ; turn all LEDs ON
PORTA = 0x00 ; turn all LEDs OFF
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(100);
PORTB = 0x00 ; turn all LEDs OFF
PORTA = 0xff ; turn all LEDs ON
PORTA = 0xff ; turn all LEDs ON
_delay_us(100);
PORTB = 0xff ; turn all LEDs ON
PORTA = 0x00 ; turn all LEDs OFF
PORTA = 0x00 ; turn all LEDs OFF
_delay_us(100);
PORTB = 0x00 ; turn all LEDs OFF
PORTA = 0xff ; turn all LEDs ON
PORTA = 0xff ; turn all LEDs ON
_delay_us(100);
}
There are no comments on this page. [Add comment]