Advertisement
varden

Untitled

Feb 19th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. void refreshLCD(void){
  2.     LCD_Clear();
  3.    
  4.     //write status
  5.     if(isPlaying==1){      
  6.         LCD_GoTo(4,0);
  7.         LCD_WriteText("Playing!");
  8.     }
  9.     else{
  10.         LCD_GoTo(5,0);
  11.         LCD_WriteText("Paused");
  12.     }  
  13.    
  14.     //write bpm
  15.     LCD_GoTo(0,1);
  16.     LCD_WriteText("BPM:");
  17.     LCD_WriteInteger(bpm);
  18.    
  19.     //write "currentbeat / beat"
  20.     LCD_GoTo(8,1);
  21.     LCD_WriteText("Beat:");
  22.     LCD_WriteInteger(currentBeat);
  23.     LCD_WriteText("/");
  24.     LCD_WriteInteger(beat);
  25. }
  26.  
  27. ISR(TIMER2_OVF_vect) {
  28.     ++currentOverflowCount;
  29.    
  30.     if(currentOverflowCount>=expectedOverflowCount){
  31.         TIMSK|=(1<<OCIE2);
  32.         TIMSK&=~(1<<TOIE2);
  33.     }
  34. }
  35.  
  36. ISR(TIMER2_COMP_vect){
  37.     TCNT2 = 0;
  38.     TIMSK&=~(1<<OCIE2);
  39.     TIMSK|=(1<<TOIE2);
  40.    
  41.     ++currentBeat;
  42.     if ((currentBeat % beat == 1) || (currentBeat > beat)){
  43.         tick(1);
  44.         currentBeat = 1;
  45.     }
  46.     else {
  47.         tick(0);
  48.     }  
  49.    
  50.     currentOverflowCount=0;
  51.     refreshLCD();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement