Be sure to set the configuration to HS, the standard 877A.inc file is set to XT.
Code:
;****************************************************************
;* 16F877A.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2003 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 11/06/03 *
;* Version : 2.45 *
;* Notes : *
;****************************************************************
NOLIST
ifdef PM_USED
LIST
include 'M16F87xA.INC' ; PM header
device pic16F877A, HS_osc, wdt_on, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F877A, r = dec, w = -302
INCLUDE "P16F877A.INC" ; MPASM Header
__config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST
Here is the C code to blink the leds
Code:
#include <pic.h>
__CONFIG(UNPROTECT & PWRTEN & HS & BORDIS & WDTDIS & LVPDIS);
#define LED1 RB2
#define LED2 RB1
//Just simple delay
void Delay(unsigned long cntr) {
while (--cntr != 0);
}
int main(void) {
INTCON = 0x0; // Disable inerupt
TRISB1 = 0; // Led1 pin as output
TRISB2 = 0; // Led2 pin as output
while(1) {
// led 1 on
LED1 = 1;
// led 2 off
LED2 = 0;
// Simple delay
Delay(50000);
// led 1 off
LED1 = 0;
// led 2 on
LED2 = 1;
// Simple delay
Delay(50000);
}
}
Here is a Picbasic translation
Code:
LED1 VAR PORTB.2
LED2 VAR PORTB.1
TRISB = %00000000
Main:
HIGH LED1
LOW LED2
Pause 500
LOW LED1
HIGH LED2
Pause 500
GOTO Main
end
Should work
Good luck
Bookmarks