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.

Twinkle twinkle little star...

Status
Not open for further replies.

RobertD

New Member
Hi Folks. I'm back to square one. Naturally, when I loaded my program it did not work, so I have to work in circuit, that requires a lot of switching chips around, and I'm thinking of getting a PICKIT2 programmer, and a set up like FUTZ has.

Anyway, I wrote a program to flash the LED, and it doesn't work, so I don't know why, since it does work on SIM, no problem. I'm using a 16F88. I left some of the set up files since I need them to run the complete program and want to write these test programs around them.

Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF 

 errorlevel	-302


	Cblock	0x20
	TIMER1, TIMER2, HBYTE, LBYTE,
	endc
	
	

   	banksel	TRISA		;bank 1
	movlw	0x42		;1MHz clock
	movwf	OSCCON
	movlw	0x07		;turn comparators off
	movwf	CMCON

	movlw	B'11111111'
	movwf	TRISB		
	movlw	B'00000010'	
	movwf	ANSEL
	movwf	TRISA
	movlw	B'00000000'
	movwf	OPTION_REG	
	banksel	PORTA
	clrf	HBYTE
	clrf	LBYTE
	clrf	PORTA
 	goto	start


delay
	movlw   D'150'          
   	movwf   TIMER1          
               
delay2
	movlw	D'150'			
	movwf	TIMER2
	decfsz  TIMER2,F        
	goto    $-1             
               
	decfsz	TIMER1,F		
	goto	delay2				
	return			

start 
 	movlw	0xA
	movwf	LBYTE
	movlw	0x2
	movwf	HBYTE


	
loop2
   	bsf		PORTA,6        
	bsf		PORTA,7


	call	delay
	call	delay
	clrf	PORTA       
	call 	delay
	call	delay
              

	decfsz	LBYTE,F
	goto	loop2
	decfsz	HBYTE,F
	goto	loop2

 
	end
 
Hi Folks. I'm back to square one. Naturally, when I loaded my program it did not work, so I have to work in circuit, that requires a lot of switching chips around, and I'm thinking of getting a PICKIT2 programmer, and a set up like FUTZ has.
Aint nothing like the real thing. :D You're finally coming to your senses. The sim is a fine tool for some things, but the breadboard is the only way to really know if something is going to work.

And ICSP is the only way to get things done at the experimentation stage. Jacking chips in and out takes forever, and wears the pins out too.
 
Agree with above, but there is a simple alternative to ICSP, just adapt a ZIF to your breadboard.

John
 
Robert, your Junebug works just like the PICkit2, what are you hoping the PICkit2 will offer that's different?

PS the 18F1320 is a pretty decent PIC and offers a few advantages over the 16F88. One is a built in A/D acquisition timer, much less if any bank switching and an extended instruction set. Plus your Junebug has a 18F1320 tutor built in, you can disconnect it and enable the external ICD connector with the flick of a couple of switches.
 
it doesn't work, so I don't know why, since it does work on SIM, no problem. I'm using a 16F88.
Code:
	decfsz	LBYTE,F
	goto	loop2
	decfsz	HBYTE,F
	goto	loop2
	end
Are you sure it works in SIM???? The PIC will jump off into LALA land when HBYTE reaches zero and the DECFSZ instruction skips over the "goto loop2" instruction and into unprogrammed flash memory. You need a "goto start" before the "end" directive:

Code:
	decfsz	LBYTE,F
	goto	loop2
	decfsz	HBYTE,F
	goto	loop2
	goto	start
	end
 
Last edited:
Hi Bill, I was at Creatron today, and the bossman told me about it, so I now have the same as PICKIT2 with Junebug, and can program in circuit. Very simple way to do it too. And I'm seriously considering switching over to the 18F1320, I haven't looked into the code, what I have to change, probably not much, and save myself a lot of headaches.

Can we meet again for that?

As far as this goes:

decfsz LBYTE,F
goto loop2
decfsz HBYTE,F
goto loop2
end

There is a goto start instruction after the set up files. And I figure the program will hang when it hits "end". But like you said it might not, however it does work for me, every time... But that's just an intermediary flasher program I wrote quickly to start programming the chip into the other program. Problem is it doesn't flash the little star.... :(

So I don't know what the problem is. I figured that ought to be simple enough to do, yet when I power the chip it doesn't flash the LEDs.

Just when I thought I was finished... more bugs____ :)

So I want to work as FUTZ says, the only way to do it, is in circuit.
 
Last edited:
When plugging the 16F88 directly for ICSP, do you put PGD to RB2, PGC to RB5 and VPP to RB3...?
 
Last edited:
There is a goto start instruction after the set up files. And I figure the program will hang when it hits "end". But like you said it might not, however it does work for me, every time...
All that the "end" does is tell the compiler to stop generating code. If the PIC was initially blank, then the remaining memory will contain ADDLW,0xFF. This will cause the PC to increment until it wraps around to 0x0000 again which what it will do in SIM giving the appearance of working code. But if the PIC was not blank, I'm not sure what would be in those undefined memory locations once it is programmed with your new code. Add the goto start, where I stated, and try it.
 
Last edited:
Ok kchriste, I'll try that right now.

The program flashes once, then nothing. I'm expecting to flash twelve times before stopping. It flashes once or twice the first time I run it, then stops.
 
Last edited:
Try putting a 0.1µF capacitor directly across the power pins of the PIC. Also make sure there is a 4.7KΩ-47KΩ pullup resistor on MCLR. If you want it to flash 12 times and then halt then do something like this:
Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF 

 errorlevel	-302


	Cblock	0x20
	TIMER1, TIMER2, NumFlashes
	endc
	
	

   	banksel	TRISA		;bank 1
	movlw	0x42		;1MHz clock
	movwf	OSCCON
	movlw	0x07		;turn comparators off
	movwf	CMCON

	movlw	B'11111111'
	movwf	TRISB		
	movlw	B'00000010'	
	movwf	ANSEL
	movwf	TRISA
	movlw	B'00000000'
	movwf	OPTION_REG	
	banksel	PORTA
	clrf	NumFlashes
	clrf	PORTA
 	goto	start


delay
	movlw   D'150'          
   	movwf   TIMER1          
               
delay2
	movlw	D'150'			
	movwf	TIMER2
	decfsz  TIMER2,F        
	goto    $-1             
               
	decfsz	TIMER1,F		
	goto	delay2				
	return			

start 
 	movlw	D'12'
	movwf	NumFlashes
loop2
   	bsf		PORTA,6        
	bsf		PORTA,7
	call	delay
	call	delay
	clrf	PORTA       
	call 	delay
	call	delay
 	decfsz	NumFlashes,F
	goto	loop2
hang
	goto	hang
	end
 
Last edited:
Remember both the 16F88 and the 18F1320 have debug support. Just like the simulator but using hardware. Try single stepping through your program.
 
Thanks Bill, I'm almost done with the 88, but since I'm so close to finish, I'd like to finish this with the 88 first before moving on to the more modern one. If the EEPROM gives me trouble, I might give up on the 88 and move right away. And perhaps I'll do production with the 1320. I did step through and through, and it worked. Maybe I should wire the thing differently. I just ground the PORTB pins directly, and use an internal pull up, is that OK?
The program works perfectly with the Firefly, it must be the way I wire the thing that's not right.

And Pommie thanks, Kchriste says to use a pullup resistor on the MCLR pin, I'll have to find out a diagram for that.

This is the circuit...
Should I do something with the unused pins...?

**broken link removed**
 
Last edited:
I just ground the PORTB pins directly, and use an internal pull up, is that OK?
Yes, that should be OK.
Should I do something with the unused pins...?
Just program them as outputs.
Kchriste says to use a pullup resistor on the MCLR pin, I'll have to find out a diagram for that.
I've added the pullup resistor to your diagram and clarified the LED connections as per the code you posted:
 

Attachments

  • F88.PNG
    F88.PNG
    23.8 KB · Views: 136
Last edited:
Thanks kchriste, I saved the pic.

Now I have a problem with the EEPROM. When I turn the chip off, I get 0xFF in my EEPROM registers, and the NEW register now puts this value in the read sequence and returns 255 instead of the previously entered value. In other words, the data doesn't get written into EEPROM, can you spot the error?

Code:
read
LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF 

 errorlevel	-302

		NEW   	equ     h'74'   ;EEPROM locations
		OLD 	equ     h'75'	

read
   	banksel   EEADR             ;Select Bank of EEADR
	movf 	 NEW, W  
	movwf 	 EEADR               ; Data Memory Address to 
	banksel   EECON1               ; Select Bank of EECON1
	bcf 	 EECON1, EEPGD   ; Point to Data memory
	bsf 	 EECON1, RD         ; EE Read
	banksel EEDATA                  ; Select Bank of EEDATA
	movf 	EEADR, W                                
	return
;_________________________________________________

write
   	banksel EECON1                 ; Select Bank of EECON1
	btfsc 	EECON1, WR                ; Wait for write
	goto 	$-1                        ; to complete
	banksel EEADR                     ; Select Bank of EEADR
	movf 	NEW, W                    
	movwf 	EEADR                   ;DATA Address to write
	movf 	NEW, W ;
	movwf 	EEDATA              ; DATA Value to write
	banksel EECON1                  ; Select Bank of EECON1
	bcf 	EECON1, EEPGD        ; Point to DATA memory
	bsf 	EECON1, WREN       ; Enable writes
	bcf 	INTCON, GIE        ; Disable INTs.
	movlw 	55h 
	movwf 	EECON2              ; Write 55h
	movlw 	h'AA' 
	movwf 	EECON2                ; Write AAh
	bsf 	EECON1, WR             ; Set WR bit to begin write
	bsf 	INTCON, GIE           ; Enable INTs.
	bcf 	EECON1, WREN         ; Disable writes
        	return
 
Last edited:
You need to specify both the data and the address to write to. You are using the same variable for both. I've fixed it, but it's a bit messy:

Code:
	Cblock	0x20
	EEAddress, NewData
	endc
	
NEW   	equ     h'74'   ;EEPROM locations
OLD 	equ     h'75'	

org 0x000
goto main


read
   	banksel EECON1              ; Select Bank of EECON1
	btfsc 	EECON1, WR          ; Wait for any writes
	goto 	$-1                 ; to complete (KCHRISTE)
   	banksel  EEAddress          ;Select Bank of EEAddress
	movf 	 EEAddress, W       ; <---KCHRISTE FIXED THIS  
   	banksel   EEADR             ;Select Bank of EEADR
	movwf 	 EEADR              ; Data Memory Address to 
	banksel   EECON1            ; Select Bank of EECON1
	bcf 	 EECON1, EEPGD   ; Point to Data memory
	bsf 	 EECON1, RD         ; EE Read
	banksel EEDATA                  ; Select Bank of EEDATA
	movf 	EEDATA, W            ; <---KCHRISTE FIXED THIS                    
	return						;On return EEPROM data is in W
;_________________________________________________

write
   	banksel EECON1                 ; Select Bank of EECON1
	btfsc 	EECON1, WR                ; Wait for any write
	goto 	$-1                        ; to complete
	banksel EEAddress
	movf 	EEAddress, W            ; <---KCHRISTE FIXED THIS                    
	banksel EEADR                     ; Select Bank of EEADR
	movwf 	EEADR                   ;DATA Address to write
	banksel NewData
	movf 	NewData, W ;
	banksel EEDATA
	movwf 	EEDATA              ; DATA Value to write
	banksel EECON1                  ; Select Bank of EECON1
	bcf 	EECON1, EEPGD        ; Point to DATA memory
	bsf 	EECON1, WREN       ; Enable writes
	bcf 	INTCON, GIE        ; Disable INTs.
	movlw 	55h 
	movwf 	EECON2              ; Write 55h
	movlw 	h'AA' 
	movwf 	EECON2                ; Write AAh
	bsf 	EECON1, WR             ; Set WR bit to begin write
	bsf 	INTCON, GIE           ; Enable INTs.
	bcf 	EECON1, WREN         ; Disable writes
  	return


main
	movlw NEW			; EEprom address
	movwf EEAddress
	movlw 0x47			; Data to write.
	movwf NewData
	call write
	nop ;Just filler feel free to delete
	call read ; EEProm data is in W
	nop ;Just filler feel free to delete
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top