Electronics > Projects, Designs, and Technical Stuff

thoughts on my project

<< < (10/12) > >>

Prehistoricman:
So they short to Vcc? Can you give a wiring diagram/schematic?

Notice you don't have a condition in the code for both buttons being high. BIG_SW has priority over SMALL_SW.

ali6x944:
so this the current wiring is attached below...
also, I have modified the code to solve the problem to this now:

--- Code: ---/*MAIN FUNCTION*/
void main(void)
{
    OSCFRQ =0b101; // OSCFRQ(HFFRQ0-2) SET OSCILLATOR TO 16MHz
   
    /*TRISx AND ANSELx ASSIGNMENT */
    TRISAbits.TRISA0=0; // TRISA0(RA0) BIG LIGHT DRIVE, OUTPUT
    TRISAbits.TRISA1=0; // TRISA1(RA1) SMALL LIGHT DRIVE, OUTPUT
    TRISAbits.TRISA2=1; // TRISA2(RA2) ANALOG POT, INPUT
    TRISAbits.TRISA4=1; // TRISA4(RA4) BIG LIGHT SWITCH, INPUT
    TRISAbits.TRISA5=1; // TRISA5(RA5) SMALL LIGHT SWITCH, INPUT
    ANSELAbits.ANSA0=0; // ANSELA0(ANSA0) DISABLED, INPUT DIGITAL
    ANSELAbits.ANSA1=0; // ANSELA0(ANSA1) DISABLED, INPUT DIGITAL
    ANSELAbits.ANSA2=1; // ANSELA2(ANSA2) ANALOG POT, INPUT ANALOG
    ANSELAbits.ANSA4=0; // ANSELA4(ANSA4) DISABLED, INPUT DIGITAL
    ANSELAbits.ANSA5=0; // ANSELA5(ANSA5) DISABLED, INPUT DIGITAL
   
    /*LATx STEADY-STATE*/
    LATAbits.LATA1 = 0;
    LATAbits.LATA0 = 0;
   
    /*MAIN LOOP*/
    while(1)
    {
        if((BIG_SW&&SMALL_SW)||(!BIG_SW&&!SMALL_SW))
        {
            LATAbits.LATA0 = 0; //LED OFF
            LATAbits.LATA1 = 0; //LED OFF
           
        }
        else if(SMALL_SW)
        {
            LATAbits.LATA1 = 1; //LED ON
            LATAbits.LATA0 = 0; //LED OFF
        }
        else if (BIG_SW)
        {
            LATAbits.LATA1 = 0; //LED OFF
            LATAbits.LATA0 = 1; //LED ON
        }
    }
   
}
--- End code ---
sorry for not checking it with the scope thou cus I had to do a bit of housekeeping...
soon however I will upload some.

Prehistoricman:
Does it work as you expect now?

Btw, this line

--- Code: ---if((BIG_SW&&SMALL_SW)||(!BIG_SW&&!SMALL_SW))
--- End code ---
can be changed to

--- Code: ---if (BIG_SW == SMALL_SW)
--- End code ---
to make it more readable

ali6x944:

--- Quote from: Prehistoricman on April 04, 2020, 12:13:42 am ---Does it work as you expect now?

Btw, this line

--- Code: ---if((BIG_SW&&SMALL_SW)||(!BIG_SW&&!SMALL_SW))
--- End code ---
can be changed to

--- Code: ---if (BIG_SW == SMALL_SW)
--- End code ---
to make it more readable

--- End quote ---
yes, it does logically :-+
for the code modification, it works also, and it is implemented now.
I haven't checked the electrical profile of the signal at RA0, RA1 thou, will be checking it soon.

ali6x944:
hi again,
I have checked the electrical profile of the signal at RA0, RA1:

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod