![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
The 6 LEDs on 3 pins threw me for a bit, but I think I've got it figured out now. But I can't get LED1 or LED6 to work. Here's my table: ![]() LEDs 2 thru 5 work perfect. 1 and 6, not so much. And here's the code: Code: #include <p18f1320.inc> cblock 0x00 d1 d2 d3 endc org 0x0000 bsf OSCCON,IRCF2 bsf OSCCON,IRCF1 bsf OSCCON,IRCF0 clrf TRISA clrf TRISB bcf PORTA,RA0 bcf PORTA,RA6 bcf PORTA,RA7 Main bsf PORTA,RA0 ;led1 bcf PORTA,RA6 bsf TRISA,7 call Delay call alloff bcf PORTA,RA0 ;led2 bsf PORTA,RA6 bsf TRISA,7 call Delay call alloff bsf TRISA,0 ;led3 bsf PORTA,RA6 bcf PORTA,RA7 call Delay call alloff bsf TRISA,0 ;led4 bcf PORTA,RA6 bsf PORTA,RA7 call Delay call alloff bcf PORTA,0 ;led5 bsf TRISA,6 bsf PORTA,RA7 call Delay call alloff bsf PORTA,0 ;led6 bsf TRISA,6 bcf PORTA,RA7 call Delay call alloff goto Main alloff clrf TRISA ;all leds off bcf PORTA,RA0 bcf PORTA,RA6 bcf PORTA,RA7 ; call Delay return Delay movlw 0x01 movwf d1 movlw 0x9f movwf d2 movlw 0x01 movwf d3 Delay_0 decfsz d1,f goto $+6 decfsz d2,f goto $+6 decfsz d3,f goto Delay_0 return end | |
| |
| | #2 |
|
I am guessing that you have A0 set as an analogue input, it will still work as a digital output but reads zero when it is read. The effect of this is that bsf and bcf instructions don't work correctly. Try clearing ANSEL (or similar). Edit, just checked the DS and you need to write 0x7f to ADCON1. Mike. Last edited by Pommie; 11th November 2007 at 03:36 AM. | |
| |
| | #3 |
|
Here's the blinky program for the Junebug Code: list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
LED macro x,y ; MACRO LED <PORTA>, <TRISA>
movlw x
movwf LATA ; LATA = x
movlw y
movwf TRISA ; TRISA = y
call Delay ;
endm ; end macro
Count equ 0 ; delay loop counter
org 0 ; reset vector
bsf ADCON1, 0 ; make RA0 digital
LED1 LED b'00000001', b'10111110' ; LED <PORTA>, <TRISA>
LED2 LED b'01000000', b'10111110' ; LED <PORTA>, <TRISA>
LED3 LED b'01000000', b'00111111' ; LED <PORTA>, <TRISA>
LED4 LED b'10000000', b'00111111' ; LED <PORTA>, <TRISA>
LED5 LED b'10000000', b'01111110' ; LED <PORTA>, <TRISA>
LED6 LED b'00000001', b'01111110' ; LED <PORTA>, <TRISA>
goto LED1 ; loop forever
Delay decfsz Count, f ;
goto Delay ;
return ;return
END
Last edited by blueroomelectronics; 11th November 2007 at 03:34 AM. | |
| |
| | #4 | |
| Quote:
| ||
| |
| | #5 | |
| Quote:
| ||
| |
| | #6 |
|
The 18F series has more than double the 16F instructions. The LAT instruction should be used when writing to a PORT (it avoids the RMW problem with 16F chips) The lack of most bank switching is a real bonus too | |
| |
|
| Tags |
| junebug, leds, tutor |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Junebug Assembly Tips | Krumlink | Micro Controllers | 187 | 18th May 2008 04:20 AM |
| Junebug kit ready, (PICkit2 & tutor) | blueroomelectronics | Micro Controllers | 37 | 28th October 2007 03:47 AM |
| Lab-Easy Prototyping system and the Junebug 3D drawing | blueroomelectronics | Electronic Projects Design/Ideas/Reviews | 9 | 21st October 2007 01:42 AM |
| New kit announcement, Junebug (PICKit2 & Firefly) | blueroomelectronics | Micro Controllers | 39 | 15th October 2007 03:21 AM |