/* 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(); 
}
/* 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();                                                       
}
Пример #3
0
/****************** **********************
函数名:HD7279字节接收函数	
功  能:从HD7279接收一个字节
输  入:无
返  回:一个字节
备  注:HD7279硬件函数
******************************************/
unsigned char receive_byte(void)
{
	unsigned char i,in_byte;
	
	WR7279|=clk7279;		    //clk7279=1;
	
	DR7279&=~dat7279;			//改dat7279为输入
	
	long_delay();
	
	for(i=0;i<8;i++)
	{	
		WR7279|=clk7279;		//clk7279=1;
		short_delay();
		in_byte=in_byte<<1;
		if(RD7279&dat7279)
		{
			in_byte=in_byte|0x01;
		}
		WR7279&=~clk7279;		//clk7279=0;
		short_delay();
	
	}
	DR7279|=dat7279;			//dat7279还原为输出口
	return(in_byte);
}
Пример #4
0
/****************** **********************
函数名:HD7279字节发送函数	
功  能:HD7279发送一个字节
输  入:一个字节
返  回:无
备  注:HD7279硬件函数
******************************************/
void send_byte(unsigned char out_byte)
{	
	unsigned char i;
	
	WR7279&=~clk7279;		    //clk7279=0;
	WR7279&=~cs7279;		    //cs7279=0
	long_delay();
	
	for(i=0;i<8;i++)
	{
		if(out_byte&0x80)
		{
			WR7279|=dat7279;	//dat7279=1;
		 }
		 else
		 {
		 	WR7279&=~dat7279;	//dat7279=0;
		 }
		 WR7279|=clk7279;		//clk7279=1;
		 short_delay();
		 WR7279&=~clk7279;		//clk7279=0;
		 short_delay();
		 out_byte=out_byte<<1;
	 }
	 WR7279|=dat7279;			//dat7279=1; 	 
}
/* 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();                                          
}
/* 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();            
}
Пример #7
0
void adxl345_init(void) {
	//set adxl to constant measurement mode
	i2c_start(ADXL345_ADDR + I2C_WRITE);
	i2c_write(0x2D);
	//set measurement bit (bit 3)
	i2c_write( (1<<3) );
	i2c_stop();
	long_delay(10);
}
Пример #8
0
void LCD_Write(unsigned char *this_text)
{
	unsigned char i = 0;
	while(this_text[i] != 0) 
	{
		lcd_write_byte(this_text[i++]);
		long_delay();
	}
}
/* Wait until a SMS arrives */
void wait_4_msg(void) {
	unsigned char dummy;
	x = 0;
	while(x != 0) 
		x=0;
	dummy = RCREG;
	PIR1bits.RCIF = 0;
	while(PIR1bits.RCIF != 1);
	long_delay();                 
}
Пример #10
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();    
}
Пример #11
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();               
} 
Пример #12
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();                                                    
}
Пример #13
0
void cy8c20180_config(void) {
	// this has actually never worked, used the arduino sketch 
	// in ../test_capsense/firmware to set the variables and write
	// them to the non-volatile memory (NVM)
	// note that it takes 120 ms for the chip to do that!


	//  First, we will configure the chip addresses
	//  Chip #0 will be disabled to make Chip #1 be the only one with address 0x00
	//  Then Chip #1 aka. 0x00 will be set to have address 0x01, and finally
	//  Chip #0 will be enabled again.

	// put chip #0 in reset/deactivate it by pulling XRES_PIN low
	XRES_PORT_REGISTER |= _BV(XRES_PIN);
	XRES_PORT |= _BV(XRES_PIN);

  long_delay(200);

  // CONFIGURE CHIP #1

	// unlock the I2C_DEV_LOCK register with magic codes
	i2c_start(I2C_ADDR0);
	i2c_write(I2C_DEV_LOCK);
  i2c_write(0x3C);
  i2c_write(0xA5);
  i2c_write(0x69);
	i2c_stop();

  long_delay(20);
  // chip #2: change the I2C_ADDR_DM register to I2C_ADDR1
	i2c_start(I2C_ADDR0);
  i2c_write(I2C_ADDR_DM);
	i2c_write(I2C_ADDR1);
	i2c_stop();

  long_delay(20);
  // chip #2: lock register again for change to take effect
	i2c_start(I2C_ADDR0);
	i2c_write(I2C_DEV_LOCK);
  i2c_write(0x96);
  i2c_write(0x5A);
  i2c_write(0xC3);
	i2c_stop();

  long_delay(20);
  // chip #2 now has the I2C address I2C_ADDR1

	// activate chip #0 again
	XRES_PORT &= ~_BV(XRES_PIN);
  long_delay(20);

	// configure capsense ports for both chips, 0x00 & 0x01
  for (uint8_t id=0; id<=1; id++) {
    // switch to setup mode
		i2c_start(id);
		i2c_write(COMMAND_REG);
		i2c_write(0x08);
		i2c_stop();
    
    // setup CS_ENABLE0 register
    i2c_start(id);
    i2c_write(CS_ENABLE0);
    i2c_write(0x0F);
    i2c_stop();
 //   delay(DEBUG_DELAY);
    
    // setup CS_ENABLE1 register
    i2c_start(id);
    i2c_write(CS_ENABLE1);
    i2c_write(0x0F);
    i2c_stop();
//    delay(DEBUG_DELAY);
    
    // switch to normal mode
    i2c_start(id);
    i2c_write(COMMAND_REG);
    i2c_write(0x07);
    i2c_stop();
  //  delay(DEBUG_DELAY);
  }
}
Пример #14
0
int main (void)
{	
	hw_init();
	
	while(ioport_get_pin_level(BUTTON)==1);
	delay_ms(500);
	ioport_set_pin_level(LED_BLUE,1);
	delay_ms(500);
	ioport_set_pin_level(LED_GREEN1,1);
	delay_ms(500);
	ioport_set_pin_level(LED_GREEN2,1);
	delay_ms(500);
	//ioport_set_pin_level(LED_RED,1);
	
	int val=0;
	char temp[10];
	char day[10]="none";
	char hour[10]="none";
	


	for(;;)
	{
		long_delay(3);
		ioport_set_pin_level(SHUTTER,0);
		delay_ms(500);
		ioport_set_pin_level(SHUTTER,1);
		val=ioport_get_pin_level(BUTTON);
		if(val==0)
		{
			ioport_set_pin_level(LED_BLUE,1);
			ioport_set_pin_level(LED_GREEN1,1);
			ioport_set_pin_level(LED_GREEN2,1);
			ioport_set_pin_level(LED_RED,1);
			delay_ms(200);
			ioport_set_pin_level(LED_BLUE,0);
			delay_ms(500);
			ioport_set_pin_level(LED_GREEN1,0);
			delay_ms(500);
			ioport_set_pin_level(LED_GREEN2,0);
			delay_ms(500);
			ioport_set_pin_level(LED_RED,0);
			delay_ms(500);
			//boot();
			ccp_write_io((uint8_t *)&RST.CTRL,RST_SWRST_bm);
		}
	}
	
	
	
	for (;;)
	{
		read_temp_str(&temp);
		str_of_date(&day);
		str_of_hour(&hour);
		printf("temp:%s date:%s %s\n",temp,day,hour);
		
		
		val=ioport_get_pin_level(BUTTON);
		if(val==0)
		{
			delay_ms(1000);
			val=ioport_get_pin_level(BUTTON);
			if(val==0)
			{
				ioport_set_pin_level(LED_BLUE,1);
				ioport_set_pin_level(LED_GREEN1,1);
				ioport_set_pin_level(LED_GREEN2,1);
				ioport_set_pin_level(LED_RED,1);
				delay_ms(200);
				ioport_set_pin_level(LED_BLUE,0);
				delay_ms(500);
				ioport_set_pin_level(LED_GREEN1,0);
				delay_ms(500);
				ioport_set_pin_level(LED_GREEN2,0);
				delay_ms(500);
				ioport_set_pin_level(LED_RED,0);
				delay_ms(500);
				//boot();
				ccp_write_io((uint8_t *)&RST.CTRL,RST_SWRST_bm);
			}
		}
	}
	// Insert application code here, after the board has been initialized.
}
Пример #15
0
// initialize the LCD controller
void LCD_Init(void)
{
	LCD_DATA_DDR |=	LCD_DATA_OUT_BITMASK;
	LCD_CTRL_DDR |= LCD_CTRL_OUT_BITMASK;
	LCD_CTRL &= ~( DISPLAY_EN | DISPLAY_RW | DISPLAY_RS); // Define state of control signals.

	long_delay();
	long_delay();
	long_delay();
	_lcd_write_4bit(0x03);	   // noch 8 Bit
	long_delay();
	_lcd_write_4bit(0x03);	   // noch 8 Bit
	long_delay();
	_lcd_write_4bit(0x03);	   // noch 8 Bit
	long_delay();
	_lcd_write_4bit(0x02);	   // jetzt 4 Bit
	long_delay();
	_lcd_write_command(0x28);     // 4 Bit Zweizeilig
	long_delay();
	_lcd_write_command(0x08);     // Display aus
	long_delay();
	_lcd_write_command(0x01);     // Clear
	long_delay();
	_lcd_write_command(0x06);     //Entry mode
	long_delay();
	_lcd_write_command(0x08 + 4); // Display an
	long_delay();
}