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.

New, what have I done wrong? :(

Status
Not open for further replies.

43617373

New Member
I Have been using a 16f690 to go through Nigel's tutorials, but now that my 16F88s got here I wanted to start playing around with them. I made this the same as normal and programmed it with pickit2 but when I use pickit2 to turn Vdd on, the chip does not follow the table, actually the chip does nothing at all. I assumed that it is a result of me abysmally low skill in assembly at this point but can not find where I went wrong, Can anyone help or see something wrong with the programming?

Code:
		List	p=16F88
		include <p16F88.inc>

		__CONFIG _CONFIG1,	0x3FB8

		cblock  0x20
			count
			count1
			counta
			countb
		endc

		bsf		STATUS,	RP0
		movlw	b'00000000'
		movwf	TRISB
		bcf		STATUS, RP0
		
Start	clrf	count
Read	movf	count,	w
		call	Table
		movwf	PORTB
		call 	Delay
		incf	count,	w
		xorlw	d'31'
		btfsc	STATUS,	Z
		goto	Start
		incf	count,	w
		goto	Read
		
Table	addwf	PCL,	f
		retlw	b'11111111'
		retlw	b'11111111'
		retlw	b'01111111'
		retlw	b'10111111'
		retlw	b'11011111'
		retlw	b'11101111'
		retlw	b'11110111'
		retlw	b'11111011'
		retlw	b'11111101'
		retlw	b'11111110'
		retlw	b'11111101'
		retlw	b'11111011'
		retlw	b'11110111'
		retlw	b'11101111'
		retlw	b'11011111'
		retlw	b'10111111'
		retlw	b'01111110'
		retlw	b'10111101'
		retlw	b'11011011'
		retlw	b'11100111'
		retlw	b'11100111'
		retlw	b'11011011'
		retlw	b'10111101'
		retlw	b'01111110'
		retlw	b'10111101'
		retlw	b'11011011'
		retlw	b'11100111'
		retlw	b'11100111'
		retlw	b'11011011'
		retlw	b'10111101'
		retlw	b'01111110'


Delay	movlw	d'250'			
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	end
 
Hi,
From your configuration words, low voltage programming is enabled, so you cannot use RB3 (PGM) pin as digital I/O.
Besides, RB7 and RB6 are also analog pins, you have to disable the analog selection, ANSEL to make all I/O to become digital I/O.
MCLR is also not pull up internally, do you have external pull up on this pin?
It's better practice to put the origin memory location, org 0x0000.
 
Thank you for the fast replies, I have corrected the config word, Ansel and added a small pull up resistor, I changed the first table value to 10101010 to see if portb was just all high or the first value and it did change to 10101010. So I assume it is something with the code not getting to the next table number?
 
Thank you for catching that and I think the problem is with the delay, I tried going down to blinking an led but I still get nothing but the original value I set the pin at before calling the delay.
 
No I don't see anything wrongly with the delay routine.
Check the OSCCON register, the default is 0x00. You need to change it to be 4 MHz or whatever frequency you like.
 
Here it is

Code:
		List	p=16F88
		include <p16F88.inc>

		__CONFIG _CONFIG1,	0x3F38

		cblock  0x20
			count
			count1
			counta
			countb
		endc

		org		0x00

		bsf		STATUS,	RP0
		movlw	b'00000000'
		movwf	TRISB
		movlw	0x00
		movwf	ANSEL
		bcf		STATUS, RP0

Start	clrf	count			;set counter register to zero
Read	movf	count, w		;put counter value in W
		call	Table	
		movwf	PORTB
		call	Delay
		incf	count,	F
		xorlw	d'31'			;check for last (31st) entry
		btfsc	STATUS,	Z
		goto	Start			;if start from beginning
		incf	count,	F		;else do next
		goto	Read

Table	addwf	PCL,	F
		retlw	b'10101010'
		retlw	b'11111111'
		retlw	b'01111111'
		retlw	b'10111111'
		retlw	b'11011111'
		retlw	b'11101111'
		retlw	b'11110111'
		retlw	b'11111011'
		retlw	b'11111101'
		retlw	b'11111110'
		retlw	b'11111101'
		retlw	b'11111011'
		retlw	b'11110111'
		retlw	b'11101111'
		retlw	b'11011111'
		retlw	b'10111111'
		retlw	b'01111110'
		retlw	b'10111101'
		retlw	b'11011011'
		retlw	b'11100111'
		retlw	b'11100111'
		retlw	b'11011011'
		retlw	b'10111101'
		retlw	b'01111110'
		retlw	b'10111101'
		retlw	b'11011011'
		retlw	b'11100111'
		retlw	b'11100111'
		retlw	b'11011011'
		retlw	b'10111101'
		retlw	b'01111110'


Delay   movlw   d'250'		;Delay 250 ms (4 MHz Clock)
	movwf   count1
d1	movlw   0xC7		;199
	movwf   counta
	movlw   0x01
	movwf   countb
Delay_0
	decfsz  counta, f	;inner loop takes 5 instruction cycles (5*199 = 995 cycles)
	goto 	d2
	decfsz  countb, f	;outer loop takes 4 (995+4 * 1 = 999)
d2	goto    Delay_0

	decfsz  count1, f	;(999 * 250 = 249750 / 1M =0.24975s)
	goto    d1
	retlw   0x00

	end
 
Last edited:
Hi,
Code:
Start	clrf	count			;set counter register to zero
Read	movf	count, w		;put counter value in W
		call	Table	
		movwf	PORTB
		call	Delay
		[b]movf	count,	w                        ;check is count = 31?[/b]
		xorlw	d'31'			;check for last (31st) entry
		btfsc	STATUS,	Z
		goto	Start			;if start from beginning
		incf	count,	F		;else do next
		goto	Read
Select 4 MHz internal RC oscillator by:
movlw 0x6E
movwf OSCCON

make sure the bank is selected correctly.
 
Thank you for your previous help, I still am having trouble with this though. It works correctly in MPlab simulator but when I write it to a chip that LED will stay on solid, is it possible to get an unlucky random manufacture defect in the chip I am using.

Here is the code that I am trying to get to work.

Code:
	List	p=16F88
		include <p16F88.inc>

		__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO

		__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

		cblock  0x20
			count1
			counta
			countb
		endc

		org		0x00

		bsf		STATUS,	RP0
		clrf	TRISB
		clrf	ANSEL
		movlw 	0x6E
		movwf 	OSCCON
		bcf		STATUS, RP0
		clrf	PORTB

Start	bsf		PORTB,1
		call 	Delay
		bcf		PORTB,1
		call	Delay
		goto	Start


Delay   movlw   d'250'		;Delay 250 ms (4 MHz Clock)
		movwf   count1
d1		movlw   0xC7		;199
		movwf   counta
		movlw   0x01
		movwf   countb
Delay_0
		decfsz  counta, f	;inner loop takes 5 instruction cycles (5*199 = 995 cycles)
		goto 	d2
		decfsz  countb, f	;outer loop takes 4 (995+4 * 1 = 999)
d2		goto    Delay_0

		decfsz  count1, f	;(999 * 250 = 249750 / 1M =0.24975s)
		goto    d1
		retlw   0x00

		end
 
Your code looks fine. How is your LED wired up and is it to port B bit 1, pin 7.

Mike.
 
Its is hooked up to the correct pin with its negative leg going to a 470ohm resistor to ground. I am fairly sure I have everything wired correctly except one thing, I have about a 7k ohm resistor as the pull up for the mclr, is there a certain value that is needed?
 
43617373 said:
except one thing, I have about a 7k ohm resistor as the pull up for the mclr, is there a certain value that is needed?
I've read multiple times that a 33K ohm MCLR pullup is recommended. That's what I use on all my PICs and I have no troubles whatsoever.
 
The resistor on MCLR is not the problem for 2 reasons.

1. You can tie MCLR directly to Vdd or use any value up to the recommended maximum.

2. You have MCLR turned off in your config.:D

Mike.
 
A long time ago I used an 'F88, and I remember looking at the data sheet, because I had oscillator 'issues.'

I just fired up the data sheet again, but am too tired, or too lazy right now, to scour it for the right info. I did cut this from it, though:
... using the internal oscillator
block. This is regardless of whether the
actual frequency used is INTOSC (8 MHz),
the INTOSC postscaler or INTRC
(31.25 kHz).

I'd take another look at your config for the osc. Perhaps your clock is much slower, and your LED is just on for a very long time, before the delay?
 
BeeBop said:
I'd take another look at your config for the osc. Perhaps your clock is much slower, and your LED is just on for a very long time, before the delay?
I did that once on a 18F1320. Wasted a lot of time before catching it turning off and on out of the corner of my eye while thrashing thru the datasheet. Clock was set to default ultra-slow speed.

On the 1320 I use this to set it to 8MHz internal clock:
Code:
	bsf		OSCCON,IRCF2	;set to 8MHz clock
	bsf		OSCCON,IRCF1
	bsf		OSCCON,IRCF0
I just looked it up and, YES, that will work for 16F88 as well. Default is, I think, 31.25kHz - VERY, VERY slow.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top