Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Junebug tutor LEDs

Status
Not open for further replies.

futz

Active Member
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:
truth.jpg

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
 
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:
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:
Pommie said:
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.
That was it. I should have thought of that - I've run into it before. Thanks for the pointer.
 
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 :)
 
Status
Not open for further replies.

Latest threads

Back
Top