SHARE
TWEET

Untitled

a guest Dec 22nd, 2011 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define F_CPU 8000000
  2.  
  3. #include <avr/io.h>
  4. #include <avr/interrupt.h>
  5. #include <util/delay.h>
  6. #include <avr/pgmspace.h>
  7.  
  8. #define bit_get(p,m) ((p) & (m))
  9. #define bit_set(p,m) ((p) |= (m))
  10. #define bit_clear(p,m) ((p) &= ~(m))
  11. #define bit_flip(p,m) ((p) ^= (m))
  12. #define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
  13. #define BIT(x) (0x01 << (x))
  14. #define LONGBIT(x) ((unsigned long)0x00000001 << (x))
  15. #define NOP asm("nop")
  16. #define OUT 1
  17. #define IN 0
  18.  
  19.  
  20. /*
  21. State definitions:
  22. 0 - sending out 808s
  23. 1 - NAK (0x15) was recieved, sending current settings
  24. 2 - sitting pretty
  25.  
  26. */
  27.  
  28. volatile uint8_t state=0;
  29. volatile uint8_t message[185] ={ 2, // MSG_START
  30.                     31, 0, // Selected (Number)
  31.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Phone1
  32.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Phone2
  33.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Phone3
  34.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Phone4
  35.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //Phone5
  36.                     31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38.                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  39.                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //String Data
  41.                      4 //MSG_END
  42.                      };
  43.  
  44.  
  45. ISR(USART0_RX_vect){
  46.         if(UDR0 == 0x15){
  47.                 state=1;
  48.         }
  49. }
  50.  
  51.  
  52. void usart_setup(void){
  53.         UCSR0B |= (1<<RXCIE0)|(1<<TXCIE0)|(1<< RXEN0)|(1<<TXEN1); //enable Rx and Tx as well as Rx intrrupts
  54.         UBRR0= 51; //9600 baud for 8MHz clock
  55. }
  56.  
  57. void USART_Transmit(unsigned char data){
  58.         while (! (UCSR0A & (1<<UDRE0)) ) //wait for the register to be clear, before sending another char
  59.                 ;
  60.         UDR0 = data;    //send it!
  61. }
  62.  
  63.  
  64.  
  65. int main(void){
  66.         usart_setup();
  67.         sei();
  68.         for(;;){
  69.                 switch (state){
  70.                         case 0:
  71.                                 USART_Transmit('8');
  72.                                 USART_Transmit('0');
  73.                                 USART_Transmit('8');
  74.                                 for(uint8_t j = 0; j<100; j++){
  75.  
  76.                                         _delay_ms(10);
  77.                                 }
  78.                                 break;
  79.                         case 1:
  80.                                 for(uint8_t i=0; i<185; i++){
  81.                                         USART_Transmit(message[i]);
  82.                                 }
  83.                                 state=2;
  84.                                 break;
  85.                         case 2:
  86.                                 NOP; //nothing ot do here
  87.                                 break;
  88.                         default:
  89.                                 USART_Transmit(0x01); //if this is transmitted then there was an error, it should never go to default
  90.                                 break;
  91.                 }
  92.                
  93.         }
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top