Serial makefile target
This commit is contained in:
		
							parent
							
								
									eb77cd1577
								
							
						
					
					
						commit
						f5101cff32
					
				
					 2 changed files with 31 additions and 21 deletions
				
			
		
							
								
								
									
										46
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								main.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -12,7 +12,7 @@
 | 
			
		|||
#define LED_PIN PB5  // Define the pin connected to the LED
 | 
			
		||||
#define TEMP_SENSOR_ADDR 0x48
 | 
			
		||||
#define TEMP_REG_ADDR 0x00
 | 
			
		||||
#define BAUD 9600
 | 
			
		||||
#define BAUD 9600  // 9600 seems to be the highest the ATmega328P can handle in this config
 | 
			
		||||
 | 
			
		||||
void initI2C() {
 | 
			
		||||
    // Set the prescaler to 1
 | 
			
		||||
| 
						 | 
				
			
			@ -104,25 +104,6 @@ float readTemperature() {
 | 
			
		|||
    return (float)temperature * 0.0625;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
    initI2C();
 | 
			
		||||
    initUART();
 | 
			
		||||
 | 
			
		||||
    float temperature;
 | 
			
		||||
 | 
			
		||||
    while (1) {
 | 
			
		||||
        temperature = readTemperature();
 | 
			
		||||
        // Print temperature over UART
 | 
			
		||||
        UART_println("Temperature: ");
 | 
			
		||||
        UART_transmit((uint8_t)(temperature / 10.0) + '0');
 | 
			
		||||
        UART_transmit((uint8_t)fmod(temperature, 10.0) + '0');
 | 
			
		||||
        UART_println(" °C");
 | 
			
		||||
        _delay_ms(1000);  // Delay for 1 second
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void blink() {
 | 
			
		||||
    // Set the LED pin as output
 | 
			
		||||
    DDRB |= (1 << LED_PIN);
 | 
			
		||||
| 
						 | 
				
			
			@ -139,3 +120,28 @@ void blink() {
 | 
			
		|||
        _delay_ms(500);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
    // initI2C();
 | 
			
		||||
    initUART();
 | 
			
		||||
 | 
			
		||||
    while(1) {
 | 
			
		||||
        UART_println("Hello, World!");
 | 
			
		||||
        _delay_ms(1000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // float temperature;
 | 
			
		||||
 | 
			
		||||
    // while (1) {
 | 
			
		||||
    //     temperature = readTemperature();
 | 
			
		||||
    //     // Print temperature over UART
 | 
			
		||||
    //     UART_println("Temperature: ");
 | 
			
		||||
    //     UART_transmit((uint8_t)(temperature / 10.0) + '0');
 | 
			
		||||
    //     UART_transmit((uint8_t)fmod(temperature, 10.0) + '0');
 | 
			
		||||
    //     UART_println(" °C");
 | 
			
		||||
    //     _delay_ms(1000);  // Delay for 1 second
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    // return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								makefile
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								makefile
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -9,7 +9,7 @@ MCU = atmega328p
 | 
			
		|||
QEMU_MACHINE_NAME = uno
 | 
			
		||||
 | 
			
		||||
# Compiler flags
 | 
			
		||||
CFLAGS = -std=c99 -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3
 | 
			
		||||
CFLAGS = -std=c2x -Wall -Wno-array-bounds -mmcu=$(MCU) -DF_CPU=16000000UL -O3
 | 
			
		||||
 | 
			
		||||
# Source files
 | 
			
		||||
SRCS = main.c
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ all: $(TARGET).hex
 | 
			
		|||
# Link object files
 | 
			
		||||
$(TARGET).elf: $(OBJS)
 | 
			
		||||
	$(CC) $(CFLAGS) $(OBJS) -o $(TARGET).elf
 | 
			
		||||
	avr-strip $(TARGET).elf
 | 
			
		||||
 | 
			
		||||
# Convert ELF to HEX
 | 
			
		||||
$(TARGET).hex: $(TARGET).elf
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +48,9 @@ qemu: $(TARGET).elf
 | 
			
		|||
asm: $(TARGET).hex
 | 
			
		||||
	avr-objdump -S $(TARGET).elf
 | 
			
		||||
 | 
			
		||||
serial:
 | 
			
		||||
	picocom -b 9600 /dev/ttyUSB0
 | 
			
		||||
 | 
			
		||||
# Clean
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f $(OBJS) $(TARGET).elf $(TARGET).hex
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue