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.

PIC16F877 Progaming Help

Status
Not open for further replies.

samuel_jihn64

Newbie level 3
Joined
Oct 13, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,314
I'm doing a project using PIC16F877. where if the pic detect smoke from the smoke sensor (input) it will activate the fan (1st output) for 10 second and than activate the 2nd one after the fan which is perfume (2nd Output) to spray. can any one help me check the program i make are correct or not...Thank you so much...

Code:
#include<pic.h>        //include PIC microcontroller library
//configuration//
__CONFIG(0x2FF4);    //PIC microcontroller configuration
__CONFIG(0x3FFF);    //PIC microcontroller configuration

//define declaration//
#define fan_ra RC0
#define perfume_rb RC1  

#define sensor RA0

void main()
{
    unsigned char m=0,i=0;
    ANSEL=0;
    ANSELH=0;
    
    //TRIS Configuration (input & output)//
    TRISA=0b11111111;    //configure PORT B I/O direction
    
    PORTA=0xb00000000;    //configure PORT B I/O direction
    PORTB=0xb00000000;    //configure PORT B I/O direction
    
    while (1)
    {
        if(sensor==1)
        {
            fan_ra=1;
            delay(10);
            perfume_rb=1;
        };
    }
}
 

There should only be one __CONFIG statement.
You seem to define bits on PORTC as the outputs but you don't set PORTC to output mode. You must Set TRISC bits 0 and 1 to be outputs.
Variables m and i are never used, you can leave them out.
The ADC is not used so the 'ANSEL' lines can also be removed.
The semi-colon ';' on the third line form the end is not needed.
It will loop continuously if the sensor input stays high. If I understand it's purpose, you probably want to wait for the sensor to go low at some point before repeating the loop.
Check the parameter in the delay() function, is it seconds or mS ?

Brian.
 
thanks brain....the delay time would be in second..i really not cleaver in programing PIC and i use my old PIC program for line follower and edit. thanks for your kind help...
 

If I understand it's purpose, consider this code may be more suitable:

void main()
{
while(1)
{
if(sensor == 1)
{
fan_ra = 1;
delay(10000);
fan_ra = 0;
perfume_rb = 1l
delay( xxx );
perfume_rb = 0;
}

do { } while(sensor == 1);
}
}

What I have done is added commands to turn the outputs off again after a delay, you originally left them on after being triggered the first time. I also added a 'time wasting' loop at the end so it would not repeat until the sensor stopped sending it's signal. Put a realistic value for the perfume spray where I put 'xxx'. Most compilers set the delay in milli-seconds, that's why I increased your delay time to 10,000 (= 10 seconds) but check your compiler manual to confirm this.
Brian.
 
why when i compile i'm receiving this error.

Build C:\Documents and Settings\SRSPMS\Desktop\Projek\Program\Smoke Sensor for device 16F887
Using driver C:\Program Files\HI-TECH Software\PICC\9.71a\bin\picc.exe

Executing: "C:\Program Files\HI-TECH Software\PICC\9.71a\bin\picc.exe" "-oSmoke Sensor.cof" "-mSmoke Sensor.map" --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
(1273) Omniscient Code Generation not available in Lite mode (warning)
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.71a
Copyright (C) 2010 Microchip Technology Inc.
Error [939] ; . no file arguments

********** Build failed! **********
 

I think there was some mistakes in ur program.Use 0b instead of "0xb" to represent binary. I presume smoke sensor was connected to the AN0/RA0 of the ADC.U need to configure the ADC first.PORTA=0xb00000000 is a wrong statmnt.Ur pgm required to wait for the input ie,sensor==1.
 

Also check you have the compiler set to use the correct device. The build report suggests it is a 16F887 but the earlier messages say 16F877.
"(1273) Omniscient Code Generation not available in Lite mode (warning)" just means you are using the free version which does not have some extra features, it is not an error, just a warning.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top