Пример #1
0
int main(void)
{
	//---- PORT Initializations -----
	DDRB = 0xFF; PORTB = 0x00;
	DDRA = 0x00; PORTA = 0xFF;
	DDRC = 0xFF; PORTC = 0x00; //used for LCD display
	DDRD = 0xFF; PORTD = 0x00; //used for LCD display
	
	// --- Function Initializations ---
	TimerSet(5);
	TimerOn();
	PWM_on();
	initUSART();
	setCustomCharacters();
	LCD_init();

	//---if eeprom address was not initialized----
	if(eeprom_read_byte((uint8_t*)46) == 0xFF)
		eeprom_write_byte((uint8_t*)46 , 0);
		
	//----load old high score saved in EEPROM----
	currHighScore = eeprom_read_byte((uint8_t*)46);
	
	gameStatus = 0;
	soundStatus = 0;
	lcdTick();
	
	while(1){	
		mainTick();
		playSound();
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
int main(void)
{
	//port B is output
	DDRB = 0xFF;
	
	//set and turn on timer
	TimerSet(500);
	TimerOn();
	
	//turn on PWM and set servo angle
	PWM_on();
	
	unsigned char testAngles[] = {0, 30, 60, 90, 120, 150, 180};
	unsigned char i = 0;
	//main loop
	while(1)
	{	
		
		
		if(i < 7){
			Servo_SetAngle(testAngles[i++]);
		}
		else{
			i = 0;
			Servo_SetAngle(testAngles[i++]);
		}
		
		
		while(!TimerFlag);
		TimerFlag = 0;
	}
}
Пример #3
0
int main(void)
{
	DDRA = 0x00; PORTA = 0xFF;
	DDRB = 0xFF; PORTB = 0x00;
	state = Start;
	PWM_on();
	
	while(1)
	{
		Tick();
	}
}
void SMSpeaker_tick(){
	unsigned char bOnInput = ONBUTTON;
	switch(StateSpeaker){
		case SPEAKER_INIT:
			break;
		case SPEAKER_OFF:
			PORTD = 0x01;
			PWM_off();
			break;
		case SPEAKER_ON:
			PORTD = 0x02;
			PWM_on();
			set_PWM(pitchScale[currPitch]);
			break;
		case SPEAKER_OFF_WAIT:
			PORTD = 0x04;
			break;
		case SPEAKER_ON_WAIT:
			PORTD = 0x08;
			set_PWM(pitchScale[currPitch]);
			break;
		default:
			break;
	}
	switch(StateSpeaker){
		case SPEAKER_INIT:
			StateSpeaker = SPEAKER_OFF_WAIT;
			break;
		case SPEAKER_OFF:
			if(bOnInput == 0){
				StateSpeaker = SPEAKER_OFF_WAIT;
			}
			break;
		case SPEAKER_ON:
			if(bOnInput == 0){
				StateSpeaker = SPEAKER_ON_WAIT;
			}
			break;
		case SPEAKER_OFF_WAIT:
			if(bOnInput != 0){
				StateSpeaker = SPEAKER_ON;
			}
			break;
		case SPEAKER_ON_WAIT:
			if(bOnInput != 0){
				StateSpeaker = SPEAKER_OFF;
			}
		default:
			break;
	}
	return 0;
}
Пример #5
0
int main(void)
{
	DDRB = 0xFF;
	PORTB = 0xFF;
	
	DDRA = 0x00;
	PORTA = 0xFF;
	
	PWM_on();
	
    while(1)
    {
		PWM_State_machine();
        //TODO:: Please write your application code 
    }
}
int main(void)
{
	DDRB = 1 << 6 | 1 << 0; PORTB = 0xBE;
	DDRD = 0xFF;
	DDRC = 0x03;
	
	//set and turn on system timer
	TimerSet(50);
	TimerOn();
	
	LCD_init();//initialize lcd display for use
	//build custom characters for use throughout program
	LCD_build(0,angleLcdPattern);
	LCD_build(1,sunLcdPattern);
	LCD_build(2,moonLcdPattern);
	
	ADC_init();//initialize analog to digital converter
	PWM_on();//turn on PWM and servo control
	
	//Init SM states
	LcdDisplay_State = LcdInit;
	HumanDetect_State = InitDetection;
	LightSeek_State = LightSeekInit;
	ServoControl_State = ServoInit;
	
	//main loop
	while(1)
	{
		pirSensor = GetBit(PINB,1); //get reading from pir sensor
		
		HumanDetect_TickFct();
		LightSeek_TickFct();
		ServoControl_TickFct();
		LcdDisplay_TickFct();
		while(!TimerFlag);
		TimerFlag = 0;
	}
}