spermaaa

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
Never
#include <avr/io.h>
#include <util/delay.h>
#include "hd44780s/hd44780.hpp"
#include <stdio.h>
#include "uartLib/uart.hpp"
#include "libADC/libADC.hpp"

int main(void){
	uint8_t i =0;
	char str[12];

	DDRB |= (1<< DDB2) | (1<< DDB3) | (1<< DDB4) | (1<< DDB5);
	PORTB |= (1<<PORTB2) | (1<<PORTB3) | (1<<PORTB4) | (1<<PORTB5);

	DDRD &= ~(1<<DDD0) | ~(1<<DDD1) | ~(1<<DDD2) | ~(1<<DDD3);

	LCD_Initalize();

	ADC_Init();

	while(1){
		if (!(PIND & 1<<PIND3)){
			PORTB ^= (1 << PORTB2);
			_delay_ms(300);
		}

		else if(!(PIND & 1<<PIND2)){
			LCD_GoTo(0,0);
			LCD_WriteText("button pressed");
			USART_Transmit_String("button pressed");
		}

		else if(!(PIND & 1<<PIND1)){
			sprintf(str, "sprintf: %d", i);
			LCD_GoTo(0,0);
			LCD_WriteText(str);
			USART_Transmit_String(str);
			_delay_ms(1000);
			i = i+1;
		}

		else if(!(PIND & 1<<PIND0)){
			PORTB = PORTB-1;
			_delay_ms(100);
		}
		else {
			PORTB |= (1<<PORTB2) | (1<<PORTB3) | (1<<PORTB4) | (1<<PORTB5);

			LCD_Clear();
			int adc = ADC_conversion();
			char poop[12];
			sprintf(poop, "adc: %d", adc);
			LCD_GoTo(0,0);
			LCD_WriteText(poop);
			USART_Transmit_String(poop);

		}
	}
}