Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help on PIC12 coding using Hitech C compiler and PICkit3 programmer

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
Hello,

I am working on PIC12F675 currently. I have written C code for it in MPLAB and compiled using Hitech C compiler.

I program the IC using PICkit3 and I get message that programming is successful.

But, when I actually check the status of the pins of MCU, it remains undesired one.

Even if I configure pin as output and set it to '1', it remains '0' .

Any suggestions on this?
 

Can you post or upload your code?

---------- Post added at 10:01 ---------- Previous post was at 10:00 ----------

A schematic of your circuit would be helpful as well.
 

Hi, Make sure that the comparator is turned off by writing CMCON = 0x07;

MN
 

Sorry, for late reply. I first tried by myself but could not get through it.

Code:
#include "CONFIG.h"
#include "STDTYPES.h"
#include "Timer.h"
#include "Intr.h"
#include "main.h"

 __CONFIG(INTIO);	//Set Internal Oscillator with 4MHz freq


void main()
{
	uint8_t index=100;
	INIT_IO();
GPIO3=0;
//	INIT_1SecTimer();
//	INIT_INTR();
	
//	while(PORTPIN_USB == LOW);
//	if(FLAG_CLAPSWITCH == TRUE)
//	{
		PORTPIN_PCSwitch |= TRUE;
		for(;index>100;index--);
		PORTPIN_PCSwitch &= FALSE;

//	}
}


Code:
void INIT_IO(void)
{
	CONFIG_PORTPIN_USB			|=	INPUT;
	CONFIG_PORTPIN_ClapSwitch	|=	INPUT;
	CONFIG_PORTPIN_PCSwitch		&=	OUTPUT;

TRIS3 = OUTPUT;

}


This is the associated code. I commented the some of the part. I wanted to check if MCU is behaving as desired by code or not.
 

All Hi-Tech C Compiler programs should include:

Code:
#include <htc.h>

in the main code file. The htc.h ensures the correct device specific header files are included.


What are the other header files you have already included?

Can you zip up your whole project and upload it to the forum?

This will enable me to download it and troubleshoot it much quicker.

BigDog

---------- Post added at 21:11 ---------- Previous post was at 20:55 ----------

You may want to add the device specific header file, pic12f675.h in this case, located in the include directory of the Hi-Tech C Compiler installation directory.

This header file contains the correct #defines for the configuration bits and other features of the PIC being programmed.

Reference pic12f675.h
Code:
#define __PIC12F675_H

//
// Configuration mask definitions
//


// Config Register: CONFIG
#define CONFIG               0x2007
// Oscillator Selection bits
// RC oscillator: CLKOUT function on GP4/OSC2/CLKOUT pin, RC on GP5/OSC1/CLKIN
#define FOSC_EXTRCCLK        0x31FF
// RC oscillator: I/O function on GP4/OSC2/CLKOUT pin, RC on GP5/OSC1/CLKIN
#define FOSC_EXTRCIO         0x31FE
// INTOSC oscillator: CLKOUT function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN
#define FOSC_INTRCCLK        0x31FD
// INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN
#define FOSC_INTRCIO         0x31FC
// EC: I/O function on GP4/OSC2/CLKOUT pin, CLKIN on GP5/OSC1/CLKIN
#define FOSC_EC              0x31FB
// HS oscillator: High speed crystal/resonator on GP4/OSC2/CLKOUT and GP5/OSC1/CLKIN
#define FOSC_HS              0x31FA
// XT oscillator: Crystal/resonator on GP4/OSC2/CLKOUT and GP5/OSC1/CLKIN
#define FOSC_XT              0x31F9
// LP oscillator: Low power crystal on GP4/OSC2/CLKOUT and GP5/OSC1/CLKIN
#define FOSC_LP              0x31F8
// Watchdog Timer Enable bit
// WDT enabled
#define WDTE_ON              0x31FF
// WDT disabled
#define WDTE_OFF             0x31F7
// Power-Up Timer Enable bit
// PWRT disabled
#define PWRTE_OFF            0x31FF
// PWRT enabled
#define PWRTE_ON             0x31EF
// GP3/MCLR pin function select
// GP3/MCLR pin function is MCLR
#define MCLRE_ON             0x31FF
// GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD
#define MCLRE_OFF            0x31DF
// Brown-out Detect Enable bit
// BOD enabled
#define BOREN_ON             0x31FF
// BOD disabled
#define BOREN_OFF            0x31BF
// Code Protection bit
// Program Memory code protection is disabled
#define CP_OFF               0x31FF
// Program Memory code protection is enabled
#define CP_ON                0x317F
// Data Code Protection bit
// Data memory code protection is disabled
#define CPD_OFF              0x31FF
// Data memory code protection is enabled
#define CPD_ON               0x30FF


//
// Special function register definitions
//


// Register: INDF
volatile unsigned char           INDF                @ 0x000;
// bit and bitfield definitions

// Register: TMR0
volatile unsigned char           TMR0                @ 0x001;
// bit and bitfield definitions

// Register: PCL
volatile unsigned char           PCL                 @ 0x002;
// bit and bitfield definitions

// Register: STATUS
volatile unsigned char           STATUS              @ 0x003;
// bit and bitfield definitions
volatile bit CARRY               @ ((unsigned)&STATUS*8)+0;
volatile bit DC                  @ ((unsigned)&STATUS*8)+1;
volatile bit ZERO                @ ((unsigned)&STATUS*8)+2;
volatile bit nPD                 @ ((unsigned)&STATUS*8)+3;
volatile bit nTO                 @ ((unsigned)&STATUS*8)+4;
volatile bit IRP                 @ ((unsigned)&STATUS*8)+7;
volatile bit RP0                 @ ((unsigned)&STATUS*8)+5;
volatile bit RP1                 @ ((unsigned)&STATUS*8)+6;
#ifndef _LIB_BUILD
volatile union {
    struct {
        unsigned	C                   : 1;
        unsigned	DC                  : 1;
        unsigned	Z                   : 1;
        unsigned	nPD                 : 1;
        unsigned	nTO                 : 1;
        unsigned	RP                  : 2;
        unsigned	IRP                 : 1;
    };
    struct {
        unsigned	                    : 5;
        unsigned	RP0                 : 1;
        unsigned	RP1                 : 1;
    };
} STATUSbits @ 0x003;
#endif

...
...
...

Your configuration bit derative should be similar to:

Code:
__CONFIG(WDTE_OFF & FOSC_INTRCIO & CP_OFF & CPD_OFF);

Instead of:

Code:
__CONFIG(INTIO);

I'm currently using v9.81 of the Hi-Tech C Compiler, you need to make adjustments according to your version.

BigDog

---------- Post added at 21:56 ---------- Previous post was at 21:11 ----------

I believe it would be a good idea for you to checkout the following tutorials:

**broken link removed**

They are some of the best PIC tutorials I have found Online and Offline. The cover both the baseline and midrange PICs using both Assembly and the Hi-Tech C Compiler. The initial lessons actual use the 12F629 which is very similar to the 12F675.
 
Thank you for the reply.

I am attaching whole of my project with this reply.
By the time I get your inputs, I will also keep trying to resolve the issue.

When you see whole of the project, if you have any suggestion regarding the project design, structure, coding standard or anything...please dont hesitate in putting forward. Anything you feel, I am doing wrong or following wrong practice, please let me know.
 

Attachments

  • ClapSwitch.rar
    73.5 KB · Views: 72

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top