void align_ccw(void)
	{
		clockwise=0;
	counterwise=1;
	PORTG=0x00;
	PORTG|=(1<<0);

	unsigned char degree;
	PORTC=0x02;
	degree_set_new=eeprom_read_byte(25);
    if(degree_set_new>1)     
	{	

		for(degree=0;degree<50;degree++)
		{
		PORTC=0xff;
		_delay_us(555);
		PORTG|=(1<<4);
		_delay_us(5);
		PORTG&=~(1<<4);
		}
	degree_set_new--;
	eeprom_write_byte(25,degree_set_new);
	}
	lcd_gotoxy1(5);
	lcd_string("    ");
	lcd_gotoxy1(0);
	lcd_string("CCW=");
	lcd_num(degree_set_new);
	}
void main()
{
unsigned int adc_xval,adc_yval,adc_zval;
ADCInit();
lcd_init();
while(1)
{
adc_xval=adcRead(0);
lcd_gotoxy1(1);
lcd_showvalue(adc_xval);

adc_yval=adcRead(1);
lcd_gotoxy1(4);
lcd_showvalue(adc_yval);

adc_zval=adcRead(2);
lcd_gotoxy1(7);
lcd_showvalue(adc_zval);



}


}
Ejemplo n.º 3
0
int main(void)
{
	DDRC=0xFF;
	lcd_init();	
	ADC_init();	
   for(;;)  // Loop Forever 
   { 
     
		if(1<<ADCSRA)//if converstion is complete
		{
			if(ADCH<32)
			PORTC=0b11111111;
			else if (ADCH<64)
			PORTC=0b11111110;
			else if (ADCH<95)
			PORTC=0b11111100;
			else if (ADCH<128)
			PORTC=0b11111000;
			else if (ADCH<159)
			PORTC=0b11110000;
			else if (ADCH<191)
			PORTC=0b11100000;
			else if (ADCH<223)
			PORTC=0b11000000;
			else
			PORTC=0b00000000;
		}
		lcd_gotoxy1(5);
		lcd_showvalue(ADCH);
	} 
} 
Ejemplo n.º 4
0
int main(void)
{
	unsigned char Mystring[20];

	Serial_Init();
	
	lcd_init();

	print_string("\nSTART MAIN TIMER TEST");

	Timer0_Init();
	sei();

	while(1)
	{
		if(Update_flag)
		{
			sprintf(Mystring,"%02d %02d %02d",(unsigned char)HRS_var,(unsigned char)MIN_var,(unsigned char)SEC_var);
			print_string("\n\r");
			print_string(Mystring);
			lcd_gotoxy1(0);
			lcd_string(Mystring);
			Update_flag = 0;
		}
	}
}
Ejemplo n.º 5
0
//main here
int main(void) {
	uint8_t txrxrole = 0; // 1 transmitter 0 receiver
	uint8_t i = 0;

	//nrf24l01 variables
	uint8_t bufferout[NRF24L01_PAYLOAD];
	uint8_t bufferin[NRF24L01_PAYLOAD];

	#if DEBUGENABLED == 1
	//init uart
	USART_Init(103);
	#endif
	//LCD init
	lcd_init();
	lcd_gotoxy1(0);
	
	//init nrf24l01
	nrf24l01_init();

	//init interrupt
	sei();

	txrxrole = ROLERX;         /////////////////////////////////////////////////

	#if DEBUGENABLED == 1
	if(txrxrole == ROLETX)
	uart_putc('T');
	else if(txrxrole == ROLERX)
	uart_putc('R');
	#endif

	//setup buffer
	for(i=0; i<sizeof(bufferout); i++)
	bufferout[i] = i+'a';
	for(i=0; i<sizeof(bufferin); i++)
	bufferin[i] = 0;

	//sending buffer addresses
	uint8_t sendpipe = 0;
	uint8_t addrtx0[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP0;
	uint8_t addrtx1[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP1;
	uint8_t addrtx2[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP2;
	uint8_t addrtx3[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP3;
	uint8_t addrtx4[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP4;
	uint8_t addrtx5[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP5;

	#if DEBUGENABLED == 1 && NRF24L01_PRINTENABLE == 1
	nrf24l01_printinfo(uart_puts, uart_putc);
	#endif

	//main loop
	for(;;)
	{
		if(txrxrole == ROLETX)
		{//Tx
			#if DEBUGENABLED == 1
			char pipebuffer[5];
			uart_puts("sending data, on pipe ");
			itoa(sendpipe, pipebuffer, 10);
			uart_puts(pipebuffer);
			uart_puts("... ");
			#endif

				if(sendpipe == 0){
				//set tx address for pipe 0
				nrf24l01_settxaddr(addrtx0);
				} else if(sendpipe == 1) {
				//set tx address for pipe 1
				nrf24l01_settxaddr(addrtx1);
				} else if(sendpipe == 2) {
				//set tx address for pipe 2
				nrf24l01_settxaddr(addrtx2);
				} else if(sendpipe == 3) {
				//set tx address for pipe 3
				nrf24l01_settxaddr(addrtx3);
				} else if(sendpipe == 4) {
				//set tx address for pipe 4
				nrf24l01_settxaddr(addrtx4);
				} else if(sendpipe == 5) {
				//set tx address for pipe 5
				nrf24l01_settxaddr(addrtx5);
			}

			//write buffer
			uint8_t writeret = nrf24l01_write(bufferout);

			#if DEBUGENABLED == 1
			if(writeret == 1)
			uart_puts("ok\r\n");
			else
			uart_puts("failed\r\n");
			#endif

			sendpipe++;
			sendpipe%=6;
			
			#if DEBUGENABLED == 0
		}
		#endif
		#if DEBUGENABLED == 1
		_delay_ms(1000);
		#endif
	}
	
	else if(txrxrole == ROLERX)
void motor_execute(void)
{cli();
	unsigned char degree_exec_cw;
	unsigned char degree_exec;
	unsigned char degree_exec_ccw;
	
	unsigned char variance;
	
	degree_set_new=eeprom_read_byte(25);
	
    for(degree_exec_cw=degree_set_new;degree_exec_cw<600;) // 600 for 6000 degrees
    	{
        PORTC=0x33;
        motor_dir_cw();
        for(degree=0;degree<50;degree++)
            {cli();
            PORTG|=(1<<4);
            _delay_us(555);
            PORTG&=~(1<<4);
            _delay_us(5);
            
            }
            degree_exec_cw++;
            eeprom_write_byte(25,degree_exec_cw);
             
             //sei();
            _delay_ms(4);
           
            if (flag==1)
            {
            
            degree_exec_cw=eeprom_read_byte(25);
            lcd_gotoxy2(13);
            lcd_num(degree_exec_cw);
            _delay_ms(300);
            PORTC=0x01;
            }
            
        //_delay_ms(240000);
        lcd_gotoxy1(10);
        lcd_string("   ");
        lcd_gotoxy1(10);
        lcd_num(eeprom_read_byte(25));
        }

    
   
    for(degree_exec_ccw=600;degree_exec_ccw>1;)
    {   PORTC=0x77;
        //cli();
        motor_dir_ccw();
        for(degree=0;degree<50;degree++)
        {
            PORTG|=(1<<4);
            _delay_us(555);
            PORTG&=~(1<<4);
            _delay_us(5);
        }
        degree_exec_ccw--;
        eeprom_write_byte(25,degree_exec_ccw);
        lcd_gotoxy1(10);
        lcd_string("   ");
        lcd_gotoxy1(10);
        lcd_num(eeprom_read_byte(25));
        //sei();
    }


sei();
}
int main(void)
{
   DDRD |=(1<<4)|(1<<5); //initialising PORTS of motors
   DDRD |=(1<<6)|(1<<7);
   DDRB |=(1<<0)|(1<<1); // lifting motor initialization
	 
   DDRC |=(1<<3);// initialising port of buzzer .
   DDRD |=(1<<1); 

   PORTB |= (1<<5); // activating pullups for switch
	 
	    lcd_init();
        PORTC|= (1<<1);  // initialising lcd
        lcd_gotoxy1(0);
	    

	//init();             //adc initialization    
	
   while(1)
  {
    
   c1=0;  
	lcd_gotoxy1(0);
	lcd_string("x:");
	lcd_showvalue1(currx);
	lcd_string("y:");
	lcd_showvalue1(curry);
	lcd_string("o:");
	lcd_showvalue1(ori);
	
   linefollower();
   
   
   update();
   
   takecareofobject();
     
   c1 = decide();
       
	   inch();
	   
	   
    turn(c1);
	
	
	lcd_gotoxy2(0);
	
	lcd_char(c1);
	lcd_string("ox : ");
	lcd_showvalue1(objx);
	lcd_string("oy : ");
	lcd_showvalue1(objy);
	
	//if((PINA & (1<<1))||(PINA & (1<<5)))
	//f2=0;
	if(c1=='N')
	break;
   
   }

}