Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 void main(void) { TRISC.F3 = 0x00; PORTC.F3 = 0x00; while(1) { PORTC.F3 = 1; Delay_ms(500); PORTC.F3 = 0; Delay_ms(500); } }
Check the fuses!!!! CTRL + SHIFT + E!!!
Here works fine into isis using 16MHz crystal osc on RA4+RA5 (you can use internal rc osc)!!!
Added project!!!
With and without crystal osc!!!
please help i am using following code with microc ide and proteus for simulation .. after compiling following code and uploading hex file to simulation nothing happens to pic16f676
===============================CODE===============================
void main(void) {
TRISc.Rc3 = 0x00;
while(1);{
PORTc.RC3 = 1;
delay_ms(500);
PORTc.RC3 = 0;
delay_ms(500);
}
}
===============================CODE================================
PLEASE tell someone what is going wrong in this ???
/*
Project Title: Controled LED by switches
*/
void main()
{
TRISA=0B11111111; //Configure all bit of PORTA as input
TRISB=0B00000000; //Configure all bit of PORTB as output
while (1);
{
if( TRISA.F0 == 0) //If the switch is pressed
{
PORTB.F0 = ~PORTB.F0; // Toggle LEDs on PORTB.0
Delay_ms(1000); // Delay 1000 ms
}
else
if (TRISA.F1 == 0) //If the switch is pressed
{
PORTB.F1 = ~PORTB.F1; // Toggle LEDs on PORTB.1
Delay_ms(1000); // Delay 1000 ms
}
else
if(TRISA.F2 == 0) //If the switch is pressed
{
PORTB.F2 = ~PORTB.F2; // Toggle LEDs on PORTB.2
Delay_ms(1000); // Delay 1000 ms
}
else
if(TRISA.F3 == 0) //If the switch is pressed
{
PORTB.F3 = ~PORTB.F3; // Toggle LEDs on PORTB.3
Delay_ms(1000); // Delay 1000 ms
}
else
if(TRISA.F4 == 0) //If the switch is pressed
{
PORTB.F4 = ~PORTB.F4; // Toggle LEDs on PORTB.4
Delay_ms(1000); // Delay 1000 ms
}
else
if(TRISA.F5 == 0) //If the switch is pressed
{
PORTB.F5 = ~PORTB.F5; // Toggle LEDs on PORTB.5
Delay_ms(1000); // Delay 1000 ms
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 if( TRISA.F0 == 1) //If the switch is pressed { PORTB.F0 = ~PORTB.F0; // Toggle LEDs on PORTB.0 Delay_ms(1000); // Delay 1000 ms }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 if( TRISA.F0 == 1) //If the switch is pressed { Delay_ms(30); if( TRISA.F0 == 1) //If the switch is pressed { PORTB.F0 = ~PORTB.F0; // Toggle LEDs on PORTB.0 Delay_ms(1000); // Delay 1000 ms } }
/*
Project Title: Controled LED by switches
*/
void main()
{
TRISA=0B11111111; //Configure all bit of PORTA as input
TRISB=0B00000000; //Configure all bit of PORTB as output
while (1);
{
if( TRISA.F0 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F0 == 1) //If the switch is pressed
PORTB.F0 = ~PORTB.F0; // Toggle LEDs on PORTB.0
Delay_ms(1000); // Delay 1000 ms
}
}
else
if (TRISA.F1 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F1 == 1) //If the switch is pressed
PORTB.F1 = ~PORTB.F0; // Toggle LEDs on PORTB.1
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F2 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F2 == 1) //If the switch is pressed
PORTB.F2 = ~PORTB.F0; // Toggle LEDs on PORTB.2
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F3 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F3 == 1) //If the switch is pressed
PORTB.F3 = ~PORTB.F0; // Toggle LEDs on PORTB.3
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F4 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F4 == 1) //If the switch is pressed
PORTB.F4 = ~PORTB.F4; // Toggle LEDs on PORTB.4
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F5 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F5 == 1) //If the switch is pressed
PORTB.F5 = ~PORTB.F5; // Toggle LEDs on PORTB.0
Delay_ms(1000); // Delay 1000 ms
}
}
}
}
You have to add debounce delays to all switches.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 void main(){ unsigned char led1flag = 0; TRISA = 0xFF; TRISB = 0x00; PORTA = 0x00; PORTB = 0x00; while(1){ if(TRISA.F0){ Delay_ms(30); if(TRISA.F0){ ledflag = ~ledflag; } } if(ledflag){ PORTB.F0 = ~PORTB.F0; Delay_ms(1000); } else if(!ledflag){ PORTB.F0 = 0; } } ]
From each pin of PORTA connect 10K resistor to Ground.
PORTA of PIC16F877A has ADC and Comparator functions. You have to set ADCON1 and CMCON registers for PORTA to work as digital input pins. CMCON = 0x07; and for ADCON1 see datasheet ADC section - ADCON1 register settings. In the table D represents digital. Choose the setting which makes all PORTA pins D (Digital).
TRISA=0XFF; //Configure all bit of PORTA as input
TRISB=0X00; //Configure all bit of PORTB as output
PORTA=0X00; // Clear bits to zero
PORTB=0X00; // Clear bits to zero
CMCON=0X07; // or CMCON register = 0X00000111
ADCON1=0X07; // Configure ADCON1, or ADCON1=0X06;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?