pic 12f675 to light on led

Thread Starter

sovannarith

Joined Feb 11, 2010
18
Dear All

I need your help. I try to begin my work with microcontroller. As last post I try to follow lesson on http://www.gooligum.com.au/tutorials.html but I have no pic 12f509 so I use 12f675 instead. After I write code as follow

;************************************************************************
; *
; Description: Lesson 1, example 1 *
; *
; Turns on LED. LED remains on until power is removed. *
; *
;************************************************************************
; *
; Pin assignments: *
; GP1 - indicator LED *
; *
;************************************************************************
list p=12F675
#include <p12F675.inc>
; ext reset, no code protect, no watchdog, 4Mhz int clock
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
;************************************************************************
RESET CODE 0x000 ; effective reset vector
movwf OSCCAL ; update OSCCAL with factory cal value
;***** MAIN PROGRAM
;***** Initialisation
start
movlw b'111101' ; configure GP1 (only) as an output
tris GPIO
movlw b'000010' ; set GP1 high
movwf GPIO
goto $ ; loop forever
END

And I build it success as follow

Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder (4)\mypro01.cof".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder (4)\mypro01.hex".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder (4)\mypro01.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p12F675 "12F675TMPO.ASM" /l"12F675TMPO.lst" /e"12F675TMPO.err" /o"12F675TMPo_O" /d__DEBUG=1
Message[302] C:\DOCUMENTS AND SETTINGS\SOVANNARITH\DESKTOP\NEW FOLDER (4)\12F675TMPO.ASM 19 : Register in operand not in bank 0. Ensure that bank bits are correct.
Warning[224] C:\DOCUMENTS AND SETTINGS\SOVANNARITH\DESKTOP\NEW FOLDER (4)\12F675TMPO.ASM 24 : Use of this instruction is not recommended.
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" "..\..\..\..\Program Files\Microchip\MPASM Suite\LKR\12f675.lkr" "12F675TMPo_O" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"mypro01.cof" /M"mypro01.map" /W
MPLINK 4.30.01, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

MP2HEX 4.30.01, COFF to HEX File Converter
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

Loaded C:\Documents and Settings\Sovannarith\Desktop\New Folder (4)\mypro01.cof.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Sovannarith\Desktop\New Folder (4)\mypro01.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Feb 22 11:21:36 2010
----------------------------------------------------------------------
BUILD SUCCEEDED

The question is that when I compile it to pic and I try to construct circuit to light on the led It still not work. Could you advise me on such problem?

Thank
 

retched

Joined Dec 5, 2009
5,207
did you program the hex to the pic? I only see where you compiled and converted to HEX. But I do not see that you wrote the HEX file to the PIC. Did the pic program successfully?

Which PIC hardware programmer are you using?

Are you attaching the led and resistor to the GP1 pin you have set?

measure your output pins with a meter and see which ones are putting out 5v and which ones are 0v. Measure with the red lead, and put the black lead to ground.
 

Thread Starter

sovannarith

Joined Feb 11, 2010
18
sorry I confuse saying that I used pic12f675 infect now I just have pic 16f876. First I try to use pic12f675 but I use picket2 programmer so there is no device selected in baseline from this programmer so I try to use pic 16f876 but I don't know much about this pic 16f876 cause it big large especially oscillator part.
I'm sorry with something unclear I'm saying to you cause I just start to curious with microcontroller. But I just want to start the simple project with my picket2 programmer applying with MPLAB for my beginning. So hope you can help me to overcome this difficulty.

Thank
 

AlexR

Joined Jan 16, 2008
732
One thing to check (since you have enabled the MCLR pin) is have you pulled up the MCLR pin to Vdd via a resistor. If MCLR is configured to be on then without MCLR being pulled up the chip won't work.
 
Last edited:

AlexR

Joined Jan 16, 2008
732
I just re-read the thread and now I am totally confused.

Just which PIC chip type are you using?
Does your code match whatever PIC will be used?
Does it compile without error?
Can we see the code to match your PIC type?

Also PICkit2 can in fact program the 12F675 but you will find it in Mid-range devices rather than the Baseline.
 
Last edited:

Thread Starter

sovannarith

Joined Feb 11, 2010
18
I use pic 16f876. And the code as following

;***********************************************************
;Dbt_sw2led
;Moves state of front microswitches to diagnostic leds.
;If both switches on then buzzer goes on.
;TJW 24.3.05 Tested & working 20.8.05
;***********************************************************
;
list p=16f876
include p16f876.inc

;Specify RAM labels
delcntr1 equ 20 ;used in delay SR
delcntr2 equ 21
;
;Set Configuration Word: crystal oscillator HS, WDT off,
; power-up timer on, code protect off, LV Program off.
__CONFIG _CP_OFF & _RC_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
org 00
;Initialise
start
bsf STATUS,5 ;select memory bank 1

movlw B'10000000'
movwf TRISC ;port C bits
bcf STATUS,5 ;select bank 0
main
clrf PORTC
bsf PORTC,6
bcf PORTC,6
bsf PORTC,6


here goto here

end
;*****************************


After build it shows

Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder\LED.err".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder\LED.lst".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder\mypro.cof".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder\mypro.hex".
Clean: Deleted file "C:\Documents and Settings\Sovannarith\Desktop\New Folder\mypro.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F876 "LED.ASM" /l"LED.lst" /e"LED.err" /o"LED.o" /d__DEBUG=1
Message[302] C:\DOCUMENTS AND SETTINGS\SOVANNARITH\DESKTOP\NEW FOLDER\LED.ASM 24 : Register in operand not in bank 0. Ensure that bank bits are correct.
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" "..\..\..\..\Program Files\Microchip\MPASM Suite\LKR\16F876.lkr" "LED.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"mypro.cof" /M"mypro.map" /W
MPLINK 4.30.01, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

MP2HEX 4.30.01, COFF to HEX File Converter
Copyright (c) 2009 Microchip Technology Inc.
Errors : 0

Loaded C:\Documents and Settings\Sovannarith\Desktop\New Folder\mypro.cof.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Sovannarith\Desktop\New Folder\mypro.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Feb 22 15:52:05 2010
----------------------------------------------------------------------
BUILD SUCCEEDED

I use programmer picket2 to compile to pic 16f876file:///C:/Documents and Settings/Sovannarith/Desktop/untitled.bmp. And after compile it highlighted that: Programming Successful.
But when I try construct hardware it doesn't work, led not on on portC

 

t06afre

Joined May 11, 2009
5,934
The code do not match the 16f876 at all. In order to understand your PIC MCU, you must get an overview of the MCU architecture. You should download the data sheet for this purpose. Have you done any PIC work before, are you familiar with topics like bank switching etc? Also what do you use as clock source?
You have a PICKIT 2 and that it is good start.
 

Thread Starter

sovannarith

Joined Feb 11, 2010
18
Sorry as I'm just a beginner of using pic so I try to read many books but It bit difficult with real practice. So could you give me some code for using pic 16f876 with picket2.

Thank
 

Markd77

Joined Sep 7, 2009
2,806
If you decide to go back to the 12F675 you need to disable the analog features to use the pins as digital inputs or outputs. Example 3-1 in the datasheet shows you how.
Also the osccal part in your code needs changing - see example 9-1.
I like the 12F675 - fairly powerful for a small chip.
 

t06afre

Joined May 11, 2009
5,934
You need to build your self a simple trainer. I guess you can use the low pin count demo board as a template. you find it here http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805 look for "Low Pin Count User's Guide" But in order for this to work you must include a crystal or a RC osc in your design. It is also very important that you read section 12.1 Configuration Bits. The configuration bits must be correct for your setting. You can set them with the __CONFIG statement or from MPLAB. But you can NOT use the same settings as for the 16f690 chip used in the demo board. You will find the __CONFIG options at the end of the header file.
Another solution is that you get a 16f690 chip and just build the trainer and use the demo code
 
Top