Advertisement
Guest User

Untitled

a guest
Jan 17th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <asf.h>
  2. #include "u8g.h"
  3. #include <string.h>
  4.  
  5. u8g_t LCD;
  6. uint32_t sxpos = 0;
  7. uint16_t clockminutes = 0;
  8. char watchstring[7];
  9. //unsigned char str_out[9];
  10. //unsigned char xbuffer[3];
  11.  
  12. void draw(void)
  13. {
  14.     itoa(clockminutes,watchstring,10);
  15.     u8g_SetColorIndex(&LCD, 1);
  16.     //u8g_DrawBox(&LCD, 0, 0, 84, 48);
  17.     //u8g_DrawFrame(&LCD, 0, 0, 84, 48);
  18.     u8g_SetFont(&LCD, u8g_font_9x15);
  19.     u8g_DrawStr(&LCD, 0, 0, watchstring);
  20.     u8g_DrawStr(&LCD, 0, 25, "lol");
  21. }
  22.  
  23.  
  24.  
  25.  
  26. int main(void)
  27. {
  28.   /* select minimal prescaler (max system speed) */
  29.   CLKPR = 0x80;
  30.   CLKPR = 0x00;
  31.  
  32.   /*   
  33.     uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, SCK, mosi, Chip select, Register select, Reset);
  34.     u8g_dev_pcd8544_84x48_hw_spi
  35.     för SW måste du flytta på mosi till miso.
  36.   */
  37.  
  38.     u8g_InitSPI(&LCD, &u8g_dev_pcd8544_84x48_hw_spi, PN(1, 7), PN(1, 6), PN(1, 2), PN(1, 3), PN(1, 1));
  39.     u8g_SetRot180(&LCD);
  40.  
  41.  
  42.     // enable bit 5 "ASSR". enables external crystal
  43.     //ASSR |= (1<<6);
  44.     ASSR |= (1<<5);
  45.     u8g_Delay(250); //let external 32KHz crystal stabilize
  46.     TCCR2B |= ((1 << WGM22));
  47.     TIMSK2 |= (1 << OCIE2A); // Enable CTC interrupt
  48.     sei();
  49.     OCR2A = 1;
  50.     TCCR2B |= (1 << CS22) | (1 << CS20); // 32.768kHz / 128 = 1Hz overflow
  51.    
  52.    
  53.     DDRA |= (1 << 0);
  54.  
  55. for(;;)
  56. {
  57.     //memset(str_out, 0, 9); töm array
  58.     //strcat(str_out, "pwm: ");
  59.     //itoa(sxpos, xbuffer, 10);
  60.     //strcat(str_out, xbuffer);
  61.    
  62.     u8g_FirstPage(&LCD);
  63.     do
  64.     {
  65.         draw();
  66.     } while ( u8g_NextPage(&LCD) );
  67.    
  68.    
  69.     u8g_Delay(800); //~1fps
  70.    
  71.   }
  72.  
  73. }
  74.  
  75. ISR(TIMER2_COMPA_vect)
  76. {
  77.     PORTA ^= (1 << 0); // Toggle the LED
  78.     clockminutes++;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement