Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 8th June 2008, 09:37 PM   #16
Default

I tried this:
Code:
list p=16f88
	include (p16f88.inc)
	__CONFIG _CONFIG1, 0x2F34
	org 0
	bsf STATUS, RP0
	movlw b'00001110'
	movwf OPTION_REG
	movlw b'00111111'
	movwf TRISA
	bcf STATUS, RP0
	movlw b'10000000'
	xorwf PORTA, f
	sleep
	end
Still no blinking. Does this code presume an external oscillator? I'm not using one.
Hank Fletcher is offline  
Old 8th June 2008, 09:44 PM   #17
Default

Well the above program blinks the RA7 LED, about once a second.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th June 2008, 09:45 PM   #18
Default

Quote:
Originally Posted by Hank Fletcher View Post
Still no blinking. Does this code presume an external oscillator? I'm not using one.
Here's a working blinky for RA1 of the 16F88:
Code:
	LIST	p=16F88
	include "P16F88.inc"

	cblock	0x20		;start of general purpose registers
	d1,d2,d3
	endc

	org	0x0000
init
	banksel CMCON		;bank 1
	movlw	0x07		;turn comparators off
	movwf	CMCON
	clrf	ANSEL		;all pins digital
	clrf	TRISA		;all pins outputs
	movwf	TRISB
	banksel	PORTA		;select bank 0

main	bsf	PORTA,1
	call	delay
	bcf	PORTA,1
	call	delay
	goto	main

delay	movlw	0x15			;2499992 cycles
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x05
	movwf	d3
delay_0	decfsz	d1, f
	goto	dd2
	decfsz	d2, f
dd2	goto	dd3
	decfsz	d3, f
dd3	goto	delay_0
	return

	end
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 8th June 2008 at 09:57 PM.
futz is offline  
Old 8th June 2008, 10:12 PM   #19
Default

Quote:
Here's a working blinky for RA1 of the 16F88
I'll give that a try. I'm sure with Bill's code it's something basic I'm missing in terms of writing, compiling, programming the PIC.

Sorry to really break it down here, but do you mind walking me through it? I've successfully made a fair share of PIC programs and circuits using GCBASIC, but I'm looking to take the training wheels off! I know a lot of this might seem really obvious, but it seems the only way to troubleshoot it, so here it goes:

1) I open up MPLAB.
2) I select File> New.
3) This opens an "Untitled" window, which I notice is very bare, as in no code or even PC numbers in the margin when I type stuff in. That's new to me, because they're always there when you compile from GCBASIC.
4) I copy and paste in futz's code, but the text is all black, as in no colour-coding that I usually see in a compiled GCBASIC program. Also, the "program," "release from reset," etc icons are not present.

That's where I'm at. Can you get me to point B?
Hank Fletcher is offline  
Old 8th June 2008, 10:25 PM   #20
Default

Quote:
Originally Posted by Hank Fletcher View Post
1) I open up MPLAB.
2) I select File> New.
3) This opens an "Untitled" window, which I notice is very bare, as in no code or even PC numbers in the margin when I type stuff in.
That's because you haven't saved the file yet. Save it as blinky.asm and then you'll get your code colours.
I use the code templates located at:
C:\Program Files\Microchip\MPASM Suite\Template\Code
They provide a nice starting point for building a project. Look for the file f88temp.asm
Quote:
Also, the "program," "release from reset," etc icons are not present.
That's where I'm at. Can you get me to point B?
To get these, you need to select your programmer. Click "Programmer/Select Programmer" and select the ICD2, etc. Same goes for the debugger; you won't have any icons for it until you select which one to use.
__________________
Inside every little problem, is a big problem trying to get out.

Last edited by kchriste; 8th June 2008 at 10:29 PM.
kchriste is offline  
Old 8th June 2008, 10:30 PM   #21
Default

Quote:
Originally Posted by Hank Fletcher View Post
I'll give that a try. I'm sure with Bill's code it's something basic I'm missing in terms of writing, compiling, programming the PIC.
Well, mine is missing the config line. I need to add one. It's assuming you're setting it with MPLAB.

Here's a bad, but working, config line, shown in context with the preceding two lines:
Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, 0x3f2a
That really should have the actual definitions in there rather than just a number, so you could see at a glance what fuses you were setting. At the time I did that I didn't know any better. But it should work fine anyway. Fix it later.

Quote:
1) I open up MPLAB.
2) I select File> New.
3) This opens an "Untitled" window, which I notice is very bare, as in no code or even PC numbers in the margin when I type stuff in. That's new to me, because they're always there when you compile from GCBASIC.
4) I copy and paste in futz's code, but the text is all black, as in no colour-coding that I usually see in a compiled GCBASIC program. Also, the "program," "release from reset," etc icons are not present.

That's where I'm at. Can you get me to point B?
No.

Do this:
1. Start MPLAB
2. Click Project/Project Wizard
3. Click Next
4. Select your exact MCU from the list and hit Next
5. Select your language toolsuite (Microchip MPASM Toolsuite) and Next
6. Create a directory for it and a New Project File in that directory and Next
7. Hit next at Step Four as you don't have a source file saved yet
8. Hit Finish
9. Click Project/Add New File To Project. Be sure you're pointing to the correct directory. Name the file something.asm and hit Save.
10. Paste the source code into the window and hit CTRL-S

Assemble and program at will
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 8th June 2008 at 10:36 PM.
futz is offline  
Old 8th June 2008, 10:37 PM   #22
Default

Quote:
Originally Posted by kchriste
That's because you haven't saved the file yet. Save it as blinky.asm and then you'll get your code colours.
Yay, I have colours now!

Quote:
To get these, you need to select your programmer. Click "Programmer/Select Programmer" and select the ICD2, etc.
D'oh! I should have realized that. This has been wearing on me a bit, I think!

Quote:
Originally Posted by futz
Well, mine is missing the config line. I need to add one. It's assuming you're setting it with MPLAB.
Okay, I'll give that a try. I'm gonna go with kchriste's suggestions first, and if that doesn't work I'll try doing through the project wizard.
Hank Fletcher is offline  
Old 8th June 2008, 10:55 PM   #23
Default

Argh! That's still not working for me. Is this suppose to be making PortA.1 flash (so pin 18 of the IC)?

The only configuration bit I changed was the internal oscillator as RB6.
Hank Fletcher is offline  
Old 8th June 2008, 10:59 PM   #24
Default

No PORTA.7 pin 16
Many A ports are A/D or have comparators that have to be disabled, A7 is a digital I/O pin by default.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th June 2008, 11:26 PM   #25
Default

Quote:
No PORTA.7 pin 16
Many A ports are A/D or have comparators that have to be disabled, A7 is a digital I/O pin by default.
I'm still getting nothing.

Wait,

Did you mean pin 16 with just your code, or futz's as well?
Hank Fletcher is offline  
Old 8th June 2008, 11:47 PM   #26
Default

My code. What sort of programmer are you using?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 9th June 2008, 01:16 AM   #27
Default

OK. Here it is, complete, and all in one post, with photos.

That's a blue LED, so I used a 180 ohm resistor. For a red or green or amber LED you'd probably use a 330 ohm or even 470. Not terribly critical. But do use a current limiting resistor somewhere in that range.

It has a 33K MCLR pullup. Any value from 10K to 33K is fine. It's not critical at all.

Name:  16f88_blinky_ra1_001sm.jpg
Views: 28
Size:  121.8 KBName:  16f88_blinky_ra1_002sm.jpg
Views: 28
Size:  102.3 KBName:  16f88_blinky_ra1_003sm.jpg
Views: 28
Size:  98.8 KB

Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON
	ERRORLEVEL 0, -302

	cblock	0x20
	d1,d2,d3
	endc

	org	0x0000
init
	banksel	CMCON		;bank 1
	movlw	0x72		;8MHz internal osc
	movwf	OSCCON
	movlw	0x07		;turn comparators off
	movwf	CMCON
	clrf	ANSEL		;all pins digital
	movlw	0x00		;all pins outputs
	movwf	TRISA
	movwf	TRISB
	banksel	PORTA		;select bank 0

main	bsf	PORTA,1
	call	delay
	bcf	PORTA,1
	call	delay
	goto	main

delay	movlw	0x15
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x02
	movwf	d3
delay_0	decfsz	d1,f
	goto	dd2
	decfsz	d2,f
dd2	goto	dd3
	decfsz	d3,f
dd3	goto	delay_0
	return

	end
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 9th June 2008 at 01:23 AM.
futz is offline  
Old 9th June 2008, 01:31 AM   #28
Default

And here's the same thing in C (SourceBoost BoostC):
Code:
#include <system.h>
#include <stdio.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG, _WDT_OFF & _INTRC_IO & _LVP_OFF & _MCLR_ON

void main(void)
{
	osccon=0x72;
	cmcon=0x07;
	ansel=0;
	trisa=0;
	while(1){
		porta.1=1;
		delay_ms(500);
		porta.1=0;
		delay_ms(500);
	}
}
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 9th June 2008, 02:47 AM   #29
Default

Still nothing. Once I've saved the .asm, how do I get the .hex file? I've been going to file>export, then leaving the options as they are, and then saving as a .hex file. Then I import the .hex file. Is that right?
Hank Fletcher is offline  
Old 9th June 2008, 03:00 AM   #30
Default

It would help if we knew the programmer / software you're using. Some do not import the config fuses properly.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Reply

Tags
mplab, problem, programming or compiling

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Programming C in MPLAB simrantogether Micro Controllers 11 11th February 2008 07:40 PM
Programming PICC through MPLAB MatrixPhreak Micro Controllers 25 9th December 2007 04:56 PM
Programming HEX file with MPlab/Inchworm gregmcc Micro Controllers 4 27th April 2007 04:20 PM
compiling with MPLAB evandude Micro Controllers 4 9th April 2005 09:08 AM
Compiling 16F628A - problem kenmac Micro Controllers 4 23rd September 2004 06:00 AM



All times are GMT. The time now is 06:31 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker