• 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.

Problems with programing a PIC12F675

Status
Not open for further replies.

delha87

New Member
We are trying to program a PIC12F675. Our project the control of the comfort of a greenhouse.

Inputs: - temperature sensor (voltage proportional to temperature, analog input)
- humidity sensor (two states 1 or 0)
Outputs: opening windows, irrigation, resistance, ventilator

If someone could give it a look and tell us what's wrong we'll be really pleased! We think the error could be that there is some missing register or something like that. Thanks!

Source code:
#include "DEFINITIU.h"

//***************************************************************************
//Main() - Rutina principal
//***************************************************************************

int c;

int TEMPERATURA;

void main(void)
{



Init();

while(1)
{

c=0;

sensor_T();

if ( TEMPERATURA < 128 )
{
encendre_resistencia; //swich on resistance
}

apagar_resistencia;

if ( TEMPERATURA > 128 )
{
while (c < 3)
{
obrir_ventilador; //swich on ventilator
c=c+1;
}
obrir_finestres; //open windows
}

apagar_ventilador; // swich off ventilator

tancar_finestres; //close windows

}



if (SHUM==FALSE) // there's no humidity
{
REG==ON; //swich on irrigation
}

else
{
GPIO2==OFF; //swich off irrigation
}


}

// Initialization Routine //
void Init()
{
TRISIO = 0b11000010;
GPIO = 0b00000101;
ANSEL = 0b00010001;
ADCON0 = 0b00000001;
return;
}

// Temperature sensor function //

void sensor_T(void)
{
GODONE = 1; // Swich on A/D converter

while(GODONE==1) // waits until A/D coneverter is done (GODONE=0)
{
//It does nothing
}

TEMPERATURA = ADRESH;

}

//////////////////////////////////////////////
// OUTPUTS FUNCTIONS //
/////////////////////////////////////////////

// Obrir el ventilador //
void obrir_ventilador(void)
{
GPIO4==1;
}

// Tancar el ventilador //
void apagar_ventilador (void)
{
GPIO4==0;
}


// Encendre la resistència //
void encendre_resistencia(void)
{
GPIO5==1;
}

// Apagar la resistència //
void apagar_resistencia(void)
{
GPIO5==0;
}

// Obrir les finestres //
void obrir_finestres(void)
{
GPIO3==1;
}

// Tancar les finestres //
void tancar_finestres (void)
{
GPIO3==0;
}

Header code:

#include <pic.h>

__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTDIS & INTIO);


//Defines

#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define SHUM GPIO0
#define REG GPIO2

//Function Prototypes

void Init(void);
void encendre_resistencia(void);
void obrir_ventilador(void);
void obrir_finestres(void);
void apagar_resistencia(void);
void apagar_ventilador (void);
void tancar_finestres (void);
void sensor_T(void);
 

tresca

Member
What is the error ? Compiler error ? Execution ?

If execution error, what should it return, and what is it that you are getting ?
 

delha87

New Member
the error is that when we put the microchip in his circuit it doesn't do what he is mean to. It only does the "Init()" function but it doesn't do the functions that link the inputs with the outputs.

Thanks!
 

Pommie

Well-Known Member
Most Helpful Member
When you post code if you type [code] before it and [/code] after it then it will keep it's formating and be much easier to read.

Anyway, should the following,
Code:
if ( TEMPERATURA < 128 )
    {
    encendre_resistencia; //swich on resistance
}
    apagar_resistencia;
be,
Code:
if ( TEMPERATURA < 128 )
    {
    encendre_resistencia; //swich on resistance
}else{
    apagar_resistencia;
}
I think the way the code is currently, it is always turning the resistance off.

Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top