Code

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Code as PDF for free.

More details

  • Words: 241
  • Pages: 2
// blink.c compiled with codevisionavr 1.0006 // wichit sirichote 26-02-43 #include <90s8535.h> #include <delay.h> #define xtal 8000000 unsigned char counter1,flag1; bit enable_tone,off_hook; void tick_wait(){ while((tifr&0x01) == 0); //cputick <10); tcnt0 = 256-75; //78; // reload timer 0 for 100hz tick generation tifr |= 0x01; // clear timer 0 overflow flag by writing '1' } void task1(){ counter1++; if (counter1 >100) {portc ^= 0x80; counter1 = 0; flag1 ^= 0x01; // toggle flag1.0 enable_tone ^= 1; // toggle enable_tone bit } } void on_tone(){ tccr2 = 0x1e; }

// enable oc2 toggle for tone generation

void off_tone(){ tccr2 = 0x2e; }

// turn oc2 low

void test_tone(){ if (enable_tone == 1) //((flag1&0x01) != 0) on_tone(); else off_tone(); } void main() { // initialize corresponding port ddra=0x00; /* all port a is ddrb=0xff; /* all port b is ddrc=0xff; /* all port c is ddrd=0x80; /* port d is input portb=0x00; portc=0x00;

input output output except

*/ */ */ pd7 for oc2 output

flag1 = 0; // timer0 is used for system 10ms tick timsk = 0x01; tccr0 = 0x05;

// timer 0 overflow enable // start timer0 with clk/1024

*/

// timer2 is used for 550hz tone generation, the real output measured via fluke83 is 558hz ocr2 = 28; // toggle oc2 every 1/1116hz or 558hz output frequency tccr2 = 0x1e; // start timer2 with pclk/256, reset timer2 when matched while (1) { tick_wait(); test_tone(); //on_tone(); task1(); } }

// 10ms tick

Related Documents

Code
June 2020 11
Code
November 2019 28
Code
July 2020 8
Code
October 2019 32
Code
November 2019 26
Code
June 2020 9