Justin Wenger
Newbie level 5
guys, I want to make a UART code that prints '........' permanently and when I Interrupt(with INT0), it prints 'ppppp' instead, and when I interrupt again(with INT1), it prints '.....'again.
But the interrupt part isn't working.. The code works well printing '....' but even if I press INT0, nothing changes and it keeps printing '...'
if someone knows what the problem with this code is, please share your wisdom
But the interrupt part isn't working.. The code works well printing '....' but even if I press INT0, nothing changes and it keeps printing '...'
if someone knows what the problem with this code is, please share your wisdom
Code:
#define F_CPU 16000000
#include <avr/io.h>
#include <avr/interrupt.h>
void uart0_init(void);
int Putchar(char message);
int x=0;
int main(void)
{
uart0_init();
while(1)
{
if(x==0)
{
Putchar('.');
}
if(x==1)
{
Putchar('p');
}
}
}
int interrupt(void)
{
EICRA = 0x0F; // Rising Edge detection
EIMSK = 0x03; // Set INT0 & INT1
SREG |= 0x80; // Global Interrupt Enable
while(1)
{
}
}
ISR(INT0_vect)
{
x++;
}
ISR(INT1_vect)
{
x--;
}
void uart0_init(void) {
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x67; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
}
int Putchar(char message) {// Putchar "P" cVde
while (((UCSR0A>>UDRE0)&0x01) == 0) ; // UDRE, data register empty
UDR0 = message;
return 0;
}
Last edited by a moderator: