This project is an optical encoder designed to encode 62 numerical characters (0-9, a-z, A-Z) from a keyboard over a serial channel and output these encoded characters to 6 LEDs. The project is written in embedded C and designed to run on an ATMEGA328 MCU interfaced with an FT232RL USB to Serial adapter.
delay.h
: Defines functions for millisecond and microsecond delays.led.h
: Contains function prototypes for LED control and initialization.reg_map.h
: Defines the registers in the ATMega328/P microcontroller.usart.h
: Defines functions for serial communication with a terminal emulator.util.h
: Contains utility function prototypes, such as division modulus.
led.c
: Implements the LED control and initialization functions.interrupt.c
: Contains code to handle interrupts.util.c
: Implements utility functions.usart.c
: Defines functions used for communication with the terminal emulator.oencoder.c
: The main file implementing the optical encoder logic.Makefile
: Contains the build instructions for the project.
init_led()
: Initializes the LEDs. This function must be called before using the LED ON and OFF functions.- LED ON/OFF Functions: Implemented in
led.c
and the prototypes are defined inled.h
.
delay_ms()
: Introduces a delay in milliseconds.delay_us()
: Introduces a delay in microseconds.
reg_map.h
: Contains definitions for the registers in the ATMega328/P microcontroller.
interrupt.c
: Contains the code required to handle interrupts appropriately.
util.c
: Implements various utility functions such as division modulus operations.util.h
: Contains the corresponding function prototypes.
usart.c
&usart.h
: Define functions for communicating with a terminal emulator running on the development PC.sscanc()
: Reads a character from the terminal emulator.init_usart()
: Initializes the serial communication channel.- Error Handling:
sscanc()
may return errors which should be handled accordingly in the implementation.
Use the following configuration for Tera Term or Screen:
- Speed: 9600
- Data: 8-bit
- Parity: None
- Stop bits: 1 bit
- Flow control: None
- ATMEGA328 MCU
- FT232RL USB to Serial adapter
- 6 LEDs
- Development PC with terminal emulator (e.g., Tera Term, Screen)
- Initialize the LEDs by calling
init_led()
. - Set up the serial communication by calling
init_usart()
with the correct configuration. - Compile the project using the provided
Makefile
. - Upload the compiled code to the ATMEGA328 MCU.
- Run the terminal emulator with the specified configuration to start encoding characters and observe the LED outputs.