Ejemplo n.º 1
0
/* Once a SMS message has arrived and its index has been found, read it from 
 * SIM to local buffer ("AT+CMGR="). */
void read_msg(void) { 
	x = 0;
	while( x!= 0) 
		x=0;
	for(a=0;a<8;a++)             
		tx_char(at_cmd_8[a]);                    
	tx_char(msg_index);        
	tx_char(CR);               
	long_delay();          
	long_delay();
	long_delay(); 
}
Ejemplo n.º 2
0
/* Send location info to given mobile number using SMS */
void send_loc(void) {
	unsigned char c;
	c = 0;
	/* We have appended null character already at the end so send data 
	 * until it is found */
	while(msg_buf[c] != NULL) {
		tx_char(msg_buf[c]);
		c++;                                      
	}

	tx_char(CTRLZ); 
	long_delay();    
}
Ejemplo n.º 3
0
int inputbuffer_check(void){
	if(inputbuffer=='a'){
		tx_char('a');
		start_rx=1;
}
	return 0;
}
Ejemplo n.º 4
0
/*------------------------------------------------------------------------
  main - 
|------------------------------------------------------------------------*/
void main(void)
{
  PCON = 0x80;  /* power control byte, set SMOD bit for serial port */
  SCON = 0x50;  /* serial control byte, mode 1, RI active */
  TMOD = 0x21;  /* timer control mode, byte operation */
  TCON = 0;     /* timer control register, byte operation */

  TH1 = 0xFA;   /* serial reload value, 9,600 baud at 11.0952Mhz */
  TR1 = 1;      /* start serial timer */

  EA = 1;       /* Enable Interrupts */

  TI = 0;       /* clear this out */
  SBUF = '.';   /* send an initial '.' out serial port */
  //ES = 1;                           /* Enable serial interrupts IE.4 */

  tx_str("Hello World\n");

  RI = 0;
  g_dc = 0;
  for (;;)
  {
    if (RI)  // we have new serial rx data
    {
      g_dc = SBUF;  // read the serial char
      RI = 0;  // reset serial rx flag

      tx_char(g_dc);   // echo back out as serial tx data
      if ((g_dc == 0x0d) || (g_dc == '.') || (g_dc == 0x0a)) // if CR, then end of line
      {
        tx_char(0xd);  // CR
        tx_char(0xa);  // LF
        lbuf[li] = 0;
        li = 0;
        tx_str("You typed in this[");
        tx_str(lbuf);
        tx_str("]\n");
      }
      else
      {
        lbuf[li] = g_dc;
        if (li < 11)
          ++li;
      }
    }
  }
}
Ejemplo n.º 5
0
int inputbuffer_check(void){
	if(inputbuffer=='a'){
		PORTC^=(1<<PC4);
		_delay_ms(1000);
		tx_char('a');
}
	return 0;
}
Ejemplo n.º 6
0
/* Set the new message indicators ("AT+CNMI=1,1,0,0,1\r") */
void cmd_6(void) { 
	x = 0;
	while(x != 0) 
		x=0;
	for(a=0; a<18; a++)             
		tx_char(at_cmd_6[a]);                
	long_delay();                                          
}
Ejemplo n.º 7
0
/* Just ping modem for basic AT command ("AT\r") */
void cmd_2(void) { 
	x = 0;
	while (x != 0) 
		x=0;
	for(a=0; a<3; a++)             
		tx_char(at_cmd_2[a]);                       
	long_delay();            
}
Ejemplo n.º 8
0
//*********************************************************************
// Do function for regdflt, called when the terminating carriage return
// is received.
// Scans through the array of registers, storing the default value
// of each.
//*********************************************************************
void do_rdflt ( void )
{
#if defined(__CODEVISIONAVR__)
    flash register_defs_t * ptr_reg_def ;
#elif defined(__GNUC__)
    register_defs_t * ptr_reg_def ;
#endif
    uint8_t reg_num ;
    uint8_t reg_offset ;
    void (*fp)(uint8_t);
    
    reg_num = 0 ;
    do {
        // Get a pointer to the register group, if any.
        ptr_reg_def = regrw_find_reg_group ( reg_num ) ;
        if ( ptr_reg_def == NULL )
        {
            continue ;
        }
        
        // Get the offset of the register in the group.  The offset
        // is 0 for registers 0-31; otherwise it is reg_num % 32 (i.e.
        // the least significant 5 bits of reg_num).
        if ( reg_num < 32 )
        {
            reg_offset = 0 ;
        }
        else
        {
            reg_offset = reg_num & 0x1F ;
        }

        // Call the write handler.
        cmd_arg_int = pgm_word(ptr_reg_def->default_value) ;
        cmd_arg_positive = TRUE ;   // Assume all default values positive
	fp = (void (*)(uint8_t))pgm_word(ptr_reg_def->ptr_write_handler);
	fp( reg_offset ) ;
     } while ( ++reg_num != 0 ) ;

     // Transmit completion message:  "OK\n"
     tx_char ( 'O' ) ;
     tx_char ( 'K' ) ;
     tx_char ( 0x0D ) ;
}
Ejemplo n.º 9
0
/* Instruct GSM modem that we need to send an SMS */
void send_msg_cmd(void) {
	for(a=0; a<8; a++)             
		tx_char(at_cmd_9[a]);                   
	tx_char('"');
	tx_char('+');
	tx_char('9');
	tx_char('1'); 
	for(a=0; a<10; a++)             
		tx_char(mob_no_buf[a]);                    
	tx_char('"');
	tx_char(CR);
	long_delay();               
} 
Ejemplo n.º 10
0
/* Delete all SMS from SIM */
void clean_sim(void) {
	x = 0;
	while(x!= 0) 
		x=0;
	for(a=0; a<12; a++)             
		tx_char(at_cmd_7[a]);                
	long_delay();  
	long_delay();
	cmd_2();                  
	if(gsm_buf[13]=='3' && gsm_buf[13]=='1' && gsm_buf[13]=='4' )                            
		long_delay();                                                       
}
Ejemplo n.º 11
0
int main(void){
	_delay_ms(1000);
	init();
	while(1){	
			if(!bitprocess()){
				if(start_rx==0){
					inputbuffer_check();
				}
				else{
					if(cd_ib==8){
						tx_char(inputbuffer);
						start_rx=0;
						cd_ib=0;
					}
				}
				// check buffer once. 
			}
		}

	return 0;

}
Ejemplo n.º 12
0
/*------------------------------------------------------------------------
  tx_str - transmit(tx) a string out the serial uart.
|------------------------------------------------------------------------*/
void tx_str(char *str)
{
  
  while (*str)
    tx_char(*str++);
}
Ejemplo n.º 13
0
/* Set SMS message storage area as SIM for every purpose ("AT+CPMS=") */
void cmd_5(void) { 
	x = 0;
	while(x != 0) 
		x=0;
	for(a=0; a<8; a++)             
		tx_char(at_cmd_5[a]);              
	tx_char('"');
	tx_char('S');
	tx_char('M');
	tx_char('"');
	tx_char(',');
	tx_char('"');
	tx_char('S'); 
	tx_char('M');
	tx_char('"');
	tx_char(',');
	tx_char('"'); 
	tx_char('S');
	tx_char('M');
	tx_char('"'); 
	tx_char(CR);              
	long_delay();                                                    
}
Ejemplo n.º 14
0
int main() {
	int oldl = 1000, oldh = 1000, oldt = 1000;//, oldr = 1000;
	unsigned char out[4];
	unsigned char rec[5];
	unsigned char temp[2];
	moduleinit();

	while (1) {
		//receive and convert temperature
		ds1631_temp(temp);
		float c = temp[0];
		if (temp[1]) {
			c += 0.5;
		}
		float f = (9*c)/5;
		int x = f +32;

		//unsigned char rmt = rx_char();

		if (low != oldl) {
			moveto(0x45);	
			stringout("   "); //clear previous number
			moveto(0x45);
			sprintf(out, "%2d", low);
			stringout(out);
			oldl = low;
		}
		if (high != oldh) {
			moveto(0x4d);
			stringout("   ");	//clear previous number
			moveto(0x4d);
			sprintf(out, "%2d", high);
			stringout(out);
			oldh = high;
		}
		if (x != oldt) {
			moveto(5);
			stringout("   ");
			moveto(5);
			itoa(x, out, 10);
			stringout(out);
			oldt = x;
			//send temperature
			if (x > 0) {
				tx_char('+');	
			}
			else if (x < 0) {
				tx_char('-');
			}
			//if 3 digits
			if (out[2] == 0) {
				tx_char('0');
				_delay_ms(5);
				tx_char(out[0]);
				_delay_ms(5);
				tx_char(out[1]);
			}
			//if 2 digits
			else {
				tx_char(out[0]);
				_delay_ms(5);
				tx_char(out[1]);
				_delay_ms(5);
				tx_char(out[2]);
			}
		}

		//receive temperature
		if (UCSR0A & (1 << RXC0)) {
			// character has been received
			if (rx_char() == '+') {
				rec[0] = rx_char();	//100's digit
				if (rec[0] == '0') {		//if 100's digit is 0
					rec[0] = rx_char();
					rec[1] = rx_char();
					rec[2] = 0;
				}
				else {		//else reset rec[0] to 10's digit
					rec[1] = rx_char();
					rec[2] = rx_char();
					rec[3] = 0;
				}
			}
			
			else if (rx_char() == '-') {
				rec[0] = '-';
				rec[1] = rx_char();
				if (rec[1] == '0') {		//if 100's digit is 0
					rec[1] = rx_char();
					rec[2] = rx_char();
					rec[3] = 0;
				}
				else {		//else reset rec[0] to 10's digit
					rec[2] = rx_char();
					rec[3] = rx_char();
					rec[4] = 0;
				}
			}
			moveto(13);
			stringout("   ");
			moveto(13);
			stringout(rec);
		}

		if (x < low) {
			PORTD |= (1 << PD3);
		}
		else {
			PORTD &= ~(1 << PD3);
		}
		if (x > high) {
			PORTD |= (1 << PD2);
		}
		else {
			PORTD &= ~(1 << PD2);
		}
		moveto(0x50);	//move cursor off of screen
	}
	return 0;
}