PIC16F877 Programming Help

Discussion in 'Embedded Systems and Microcontrollers' started by samuel_john64, Oct 14, 2010.

  1. samuel_john64

    Thread Starter New Member

    Oct 14, 2010
    1
    0
    I'm doing a project using PIC16F877.Smocking room air refresher 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...

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

    //define declaration//
    #define fan_ra RB7
    #define perfume_rb RB6

    #define sensor RA0

    void main()
    {
    unsigned char m=0,i=0;
    ANSEL=0;
    ANSELH=0;

    //TRIS Configuration (input & output)//
    TRISA=0b11111111; //configure PORT A I/O direction
    TRISB=0b00000000; //configure PORT B I/O direction

    PORTA=0xb11111111; //configure PORT A I/O direction
    PORTB=0xb00000000; //configure PORT B I/O direction


    while(1)
    {
    if(sensor == 1)
    {
    fan_ra = 1;
    delay(10000);
    fan_ra = 0;
    perfume_rb = 1;
    delay( 5000 );
    perfume_rb = 0;
    }

    do { } while(sensor == 1);
    }
    }
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Do you have any problems with your program, and have you simulated it? If you use MPLAB you can always simulate/debug using MPLAB SIM. This tool is in fact your best friend in programming. And it is essential for a programmer to also master debugging.
    Microchip have free web-seminars at this site
    http://techtrain.microchip.com/webseminars/QuickList.aspx
    under the label "Development Tools" I will recommend
    http://techtrain.microchip.com/webseminars/ArchivedDetail.aspx?Active=43
    http://techtrain.microchip.com/webseminars/ArchivedDetail.aspx?Active=61
    http://techtrain.microchip.com/webseminars/ArchivedDetail.aspx?Active=137
    http://techtrain.microchip.com/webseminars/ArchivedDetail.aspx?Active=153
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I took a look at code also. Which clock speed do you use? Also Hi-tech C do not have a dealy function. But they do have _dealy,__delay_ms, and __dealy_us functions. Look them up in the manual.
     
Loading...