I want to toggle a led on ATmega328p by button through PCINT, my code:
// A program for LED Toggle by Push-button and PCINT on ATmega328p /* * LED toggle by button * LED - 1.5Kohm - D8(PB0) * BUTTON - D7(PD7/PCINT23) - 10Kohm - 5v(VCC) * BUTTON - GND */ #define F_CPU 16000000UL #include <avr/io.h> #include <util/delay.h> #include <avr/interrupt.h> volatile uint8_t pinb = 0; int main(void){ //DDRB &= ~(1<<DDB0); DDRB |= (1<<PINB0); //DDRD |= (1<<DDD7); DDRD &= ~(1<<PIND7); PCICR = (1<<PCIE2); //PCICR = 0x00000100; // Pin Change Interrupt Enable 2 PCMSK2 = (1<<PCINT23); //0x10000000; PCINT23 enabled //PCMSK2 = (1<<PIND7); while(true){ ; } } ISR(PCINT2_vect) { pinb = PINB; PORTB = PINB ^ pinb; }
It didn't work, any suggestion?