สร้างสัญญาณ สี่เหลี่ยมออกทางพอร์ท B
1. สร้างโปรเจคใหม่ และเพื่อตรวจจับสัญญาณที่ขา PB0 ให้เพิ่มคำสั่งจำลองการทำงานของออสซิลโลสโคป ด้วยคำสั่ง
.plot V(PB0)
2. เขียนโปรแกรม
#include <avr\io.h> // Most basic include files
#include <avr\interrupt.h> // Add the necessary ones
#include <avr\signal.h> // here
//
// Interrupt handler for INT0
//
ISR(TIMER0_OVF_vect)
{
PORTB = ~PORTB; //Complement PortB
TCNT0 = 55; //Preload Counter
}
// ***********************************************************
// Main program
//
int main(void) {
DDRB = 0b11111111; // All outputs
TCCR0A = 0; // initialize timer1
TCCR0B = 0; // mode 0
TCCR0B |= (1 << CS02); // no prescaler
TCNT0 = 55; // preload timer 60000
TIMSK0 |= (1 << TOIE0); // enable timer overflow interrupt
PORTB = 0xff; // Set port B =1111 1111
sei(); // Global Interrupt
while(1)
{
}
}