|
|
View previous topic :: View next topic |
Author |
Message |
rtracy Guest
|
Newbie Question: 16F877 - Flashing LEDs |
Posted: Tue Jul 27, 2004 8:10 am |
|
|
I'm using a 16F877 on Microchip's PICDEM 2 PLUS board. I wrote some simple code to flash the LEDs built onto the demo board. The problem is that no matter what I try RB3 will not go high. RB0 flashes, RB1 flashes, RB2 flashes but RB3 will not activate. I even measured at the 16F877's pin to be sure there wasn't a problem with the demo board.
Using the CCS project wizard, I set all of RB to output and double checked all configuration bits. I'm using the latest versions of the CCS compilers and the latest version of MPLAB IDE (6.60).
Thanks for any advice.
Code: | void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
while (TRUE) {
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
output_high(PIN_B1);
delay_ms(500);
output_low(PIN_B1);
delay_ms(500);
output_high(PIN_B2);
delay_ms(500);
output_low(PIN_B2);
delay_ms(500);
output_high(PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}
}
|
Code: | CCS PCM C Compiler, Version 3.206, 24798 27-Jul-04 08:48
Filename: C:\Program Files\PICC\Examples\Rob's Test Project 2.LST
ROM used: 174 words (2%)
Largest free fragment is 2048
RAM used: 7 (4%) at main() level
8 (5%) worst case
Stack: 1 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 019
0003: NOP
.................... #include "C:\Program Files\PICC\Examples\Rob's Test Project 2.h"
.................... #include <16F877.h>
.................... //////// Standard Header file for the PIC16F877 device ////////////////
.................... #device PIC16F877
.................... #list
....................
.................... #device adc=8
.................... #use delay(clock=4000000)
0004: MOVLW 22
0005: MOVWF 04
0006: MOVF 00,W
0007: BTFSC 03.2
0008: GOTO 018
0009: MOVLW 01
000A: MOVWF 78
000B: CLRF 77
000C: DECFSZ 77,F
000D: GOTO 00C
000E: DECFSZ 78,F
000F: GOTO 00B
0010: MOVLW 4A
0011: MOVWF 77
0012: DECFSZ 77,F
0013: GOTO 012
0014: NOP
0015: NOP
0016: DECFSZ 00,F
0017: GOTO 009
0018: RETLW 00
.................... #fuses NOWDT,XT, NOPUT, NOPROTECT, NOBROWNOUT, LVP, NOCPD, NOWRT, NODEBUG
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9,restart_wdt)
....................
....................
....................
....................
.................... void main()
.................... {
0019: CLRF 04
001A: MOVLW 1F
001B: ANDWF 03,F
001C: BSF 03.5
001D: BSF 1F.0
001E: BSF 1F.1
001F: BSF 1F.2
0020: BCF 1F.3
0021: MOVLW 19
0022: MOVWF 19
0023: MOVLW 66
0024: MOVWF 18
0025: MOVLW D0
0026: BCF 03.5
0027: MOVWF 18
....................
.................... setup_adc_ports(NO_ANALOGS);
*
002A: BSF 03.5
002B: BSF 1F.0
002C: BSF 1F.1
002D: BSF 1F.2
002E: BCF 1F.3
.................... setup_adc(ADC_OFF);
002F: BCF 03.5
0030: BCF 1F.0
.................... setup_psp(PSP_DISABLED);
0031: BSF 03.5
0032: BCF 09.4
.................... setup_spi(FALSE);
*
0028: MOVLW FF
0029: MOVWF 20
*
0033: BCF 03.5
0034: BCF 14.5
0035: BCF 20.5
0036: MOVF 20,W
0037: BSF 03.5
0038: MOVWF 07
0039: BCF 03.5
003A: BSF 20.4
003B: MOVF 20,W
003C: BSF 03.5
003D: MOVWF 07
003E: BCF 03.5
003F: BCF 20.3
0040: MOVF 20,W
0041: BSF 03.5
0042: MOVWF 07
0043: MOVLW 00
0044: BCF 03.5
0045: MOVWF 14
0046: BSF 03.5
0047: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
0048: MOVF 01,W
0049: ANDLW C0
004A: IORLW 08
004B: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
004C: BCF 03.5
004D: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
004E: MOVLW 00
004F: MOVWF 78
0050: MOVWF 12
0051: MOVLW 00
0052: BSF 03.5
0053: MOVWF 12
....................
....................
.................... while (TRUE) {
.................... output_high(PIN_B0);
0054: BCF 06.0
0055: BCF 03.5
0056: BSF 06.0
.................... delay_ms(500);
0057: MOVLW 02
0058: MOVWF 21
0059: MOVLW FA
005A: MOVWF 22
005B: CALL 004
005C: DECFSZ 21,F
005D: GOTO 059
.................... output_low(PIN_B0);
005E: BSF 03.5
005F: BCF 06.0
0060: BCF 03.5
0061: BCF 06.0
.................... delay_ms(500);
0062: MOVLW 02
0063: MOVWF 21
0064: MOVLW FA
0065: MOVWF 22
0066: CALL 004
0067: DECFSZ 21,F
0068: GOTO 064
....................
.................... output_high(PIN_B1);
0069: BSF 03.5
006A: BCF 06.1
006B: BCF 03.5
006C: BSF 06.1
.................... delay_ms(500);
006D: MOVLW 02
006E: MOVWF 21
006F: MOVLW FA
0070: MOVWF 22
0071: CALL 004
0072: DECFSZ 21,F
0073: GOTO 06F
.................... output_low(PIN_B1);
0074: BSF 03.5
0075: BCF 06.1
0076: BCF 03.5
0077: BCF 06.1
.................... delay_ms(500);
0078: MOVLW 02
0079: MOVWF 21
007A: MOVLW FA
007B: MOVWF 22
007C: CALL 004
007D: DECFSZ 21,F
007E: GOTO 07A
....................
.................... output_high(PIN_B2);
007F: BSF 03.5
0080: BCF 06.2
0081: BCF 03.5
0082: BSF 06.2
.................... delay_ms(500);
0083: MOVLW 02
0084: MOVWF 21
0085: MOVLW FA
0086: MOVWF 22
0087: CALL 004
0088: DECFSZ 21,F
0089: GOTO 085
.................... output_low(PIN_B2);
008A: BSF 03.5
008B: BCF 06.2
008C: BCF 03.5
008D: BCF 06.2
.................... delay_ms(500);
008E: MOVLW 02
008F: MOVWF 21
0090: MOVLW FA
0091: MOVWF 22
0092: CALL 004
0093: DECFSZ 21,F
0094: GOTO 090
....................
.................... output_high(PIN_B3);
0095: BSF 03.5
0096: BCF 06.3
0097: BCF 03.5
0098: BSF 06.3
.................... delay_ms(500);
0099: MOVLW 02
009A: MOVWF 21
009B: MOVLW FA
009C: MOVWF 22
009D: CALL 004
009E: DECFSZ 21,F
009F: GOTO 09B
.................... output_low(PIN_B3);
00A0: BSF 03.5
00A1: BCF 06.3
00A2: BCF 03.5
00A3: BCF 06.3
.................... delay_ms(500);
00A4: MOVLW 02
00A5: MOVWF 21
00A6: MOVLW FA
00A7: MOVWF 22
00A8: CALL 004
00A9: DECFSZ 21,F
00AA: GOTO 0A6
....................
....................
.................... }
00AB: BSF 03.5
00AC: GOTO 054
....................
.................... }
....................
00AD: SLEEP
Configuration Fuses:
Word 1: 3FB9 XT NOWDT NOPUT NOPROTECT NOBROWNOUT LVP NOCPD NOWRT NODEBUG |
|
|
|
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
i think it is your configuration's bits problem:) |
Posted: Tue Jul 27, 2004 8:15 am |
|
|
you can not use low voltage program, when you burn your program into your PIC MCU. If you choose the low voltage programming in configuration bits. The RB3 will see as input pin, so you can not control any LEDs by RB3. |
|
|
rtracy Guest
|
|
Posted: Tue Jul 27, 2004 8:22 am |
|
|
garyzheng:
Thanks a bunch! That was my problem.
I guess that when the manual arrives that I'll have to RTFM. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|