Automated formatting to styling guideline
This commit is contained in:
parent
624b57e56a
commit
43a64678eb
|
@ -1,11 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Author: Jake G
|
* Author: Jake G
|
||||||
* Date: 2024
|
* Date: 2024
|
||||||
* filename: LedController.c
|
* filename: LedController.c
|
||||||
* description: Abstract LED interface and control.
|
* description: Abstract LED interface and control.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __AVR_ATtiny404__
|
#ifndef __AVR_ATtiny404__
|
||||||
#define __AVR_ATtiny404__
|
#define __AVR_ATtiny404__
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,75 +12,71 @@
|
||||||
#include "LedController.h"
|
#include "LedController.h"
|
||||||
#include "avr/io.h"
|
#include "avr/io.h"
|
||||||
|
|
||||||
#define PA_B1 (1<<2)
|
#define PA_B1 (1 << 2)
|
||||||
#define PA_B2 (1<<3)
|
#define PA_B2 (1 << 3)
|
||||||
#define PA_B3 (1<<6)
|
#define PA_B3 (1 << 6)
|
||||||
#define PA_B4 (1<<7)
|
#define PA_B4 (1 << 7)
|
||||||
|
|
||||||
#define BITS_IN_BYTE (1<<2)|(1<<3)|(1<<6)|(1<<7)
|
#define BITS_IN_BYTE (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7)
|
||||||
|
|
||||||
#define HALF_BYTE_BM
|
#define HALF_BYTE_BM
|
||||||
|
|
||||||
typedef struct LedController {
|
|
||||||
void *port;
|
|
||||||
uint8_t pins[BITS_IN_BYTE];
|
|
||||||
}LedController;
|
|
||||||
|
|
||||||
static LedController controller;
|
|
||||||
|
|
||||||
|
//static LedController controller;
|
||||||
|
|
||||||
void LedControler_SetPortADefault(void);
|
void LedControler_SetPortADefault(void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uses pins: 9, 8, 12, 13
|
* Uses pins: 9, 8, 12, 13
|
||||||
*/
|
*/
|
||||||
void LedControler_SetPortBDefault(void)
|
void LedControler_SetPortBDefault(void)
|
||||||
{
|
{
|
||||||
//controller.port = &PORTA;
|
// controller.port = &PORTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedController_SetLedBitNum(void * port, uint8_t pin, uint8_t bit);
|
void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
|
||||||
|
|
||||||
void LedController_ShowByte(uint8_t byte);
|
void LedController_ShowByte(uint8_t byte);
|
||||||
|
|
||||||
|
|
||||||
void LedControler_ShowHalfByte(uint8_t byte)
|
void LedControler_ShowHalfByte(uint8_t byte)
|
||||||
{
|
{
|
||||||
byte = byte & 0x0F;
|
byte = byte & 0x0F;
|
||||||
|
|
||||||
//PORTA.DIR |= (1<<2)|(1<<3)|(1<<6)|(1<<7);
|
// PORTA.DIR |= (1<<2)|(1<<3)|(1<<6)|(1<<7);
|
||||||
PORTA.DIR |= PA_B1;
|
PORTA.DIR |= PA_B1;
|
||||||
PORTA.DIR |= PA_B2;
|
PORTA.DIR |= PA_B2;
|
||||||
PORTA.DIR |= PA_B3;
|
PORTA.DIR |= PA_B3;
|
||||||
PORTA.DIR |= PA_B4;
|
PORTA.DIR |= PA_B4;
|
||||||
//PORTA.DIR |= HALF_BYTE_BM;
|
// PORTA.DIR |= HALF_BYTE_BM;
|
||||||
|
|
||||||
// 15 = 0b1111
|
// 15 = 0b1111
|
||||||
//PORTA.OUT |= (byte & 0x0F);
|
// PORTA.OUT |= (byte & 0x0F);
|
||||||
|
|
||||||
if(byte & 0x01){
|
if (byte & 0x01)
|
||||||
|
{
|
||||||
PORTA.OUT |= PA_B1;
|
PORTA.OUT |= PA_B1;
|
||||||
}
|
}
|
||||||
if(byte & 0x02){
|
if (byte & 0x02)
|
||||||
|
{
|
||||||
PORTA.OUT |= PA_B2;
|
PORTA.OUT |= PA_B2;
|
||||||
}
|
}
|
||||||
if(byte & 0x04){
|
if (byte & 0x04)
|
||||||
|
{
|
||||||
PORTA.OUT |= PA_B3;
|
PORTA.OUT |= PA_B3;
|
||||||
}
|
}
|
||||||
if(byte & 0x08){
|
if (byte & 0x08)
|
||||||
|
{
|
||||||
PORTA.OUT |= PA_B4;
|
PORTA.OUT |= PA_B4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LedControler_ClearHalfByte(void)
|
void LedControler_ClearHalfByte(void)
|
||||||
{
|
{
|
||||||
//PORTA.OUT &= HALF_BYTE_BM;
|
// PORTA.OUT &= HALF_BYTE_BM;
|
||||||
//PORTA.OUT &= ~((1<<2)|(1<<3)|(1<<6)|(1<<7));
|
// PORTA.OUT &= ~((1<<2)|(1<<3)|(1<<6)|(1<<7));
|
||||||
PORTA.OUT &= ~PA_B1;
|
PORTA.OUT &= ~PA_B1;
|
||||||
PORTA.OUT &= ~PA_B2;
|
PORTA.OUT &= ~PA_B2;
|
||||||
PORTA.OUT &= ~PA_B3;
|
PORTA.OUT &= ~PA_B3;
|
||||||
PORTA.OUT &= ~PA_B4;
|
PORTA.OUT &= ~PA_B4;
|
||||||
//PORTA.OUT = 0x00;
|
// PORTA.OUT = 0x00;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* @brief Led Controller module
|
* @brief Led Controller module
|
||||||
* @details This file outputs a byte of data to the pins for led indication.
|
* @details This file outputs a byte of data to the pins for led indication.
|
||||||
* @author Jake G
|
* @author Jake G
|
||||||
* @date 2024-08-21
|
* @date 2024-08-21
|
||||||
* @copyright None
|
* @copyright None
|
||||||
* @file LEDCONTROLLER.h
|
* @file LEDCONTROLLER.h
|
||||||
*/
|
*/
|
||||||
|
@ -10,8 +10,20 @@
|
||||||
#ifndef LEDCONTROLLER
|
#ifndef LEDCONTROLLER
|
||||||
#define LEDCONTROLLER
|
#define LEDCONTROLLER
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A structure representing an LED
|
||||||
|
*/
|
||||||
|
typedef struct Led
|
||||||
|
{
|
||||||
|
uint8_t *port;
|
||||||
|
uint8_t pin_num;
|
||||||
|
bool state;
|
||||||
|
}Led;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default PORTB pins for output.
|
* Sets the default PORTB pins for output.
|
||||||
|
@ -23,30 +35,27 @@ void LedControler_SetPortADefault(void);
|
||||||
*/
|
*/
|
||||||
void LedControler_SetPortBDefault(void);
|
void LedControler_SetPortBDefault(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the setting or changing of which pins represent which bits.
|
* Allows the setting or changing of which pins represent which bits.
|
||||||
* @param port The address of the port.
|
* @param port The address of the port.
|
||||||
* @param pin The pin number for the port.
|
* @param pin The pin number for the port.
|
||||||
* @param bit The bit that the pin should represent.
|
* @param bit The bit that the pin should represent.
|
||||||
*/
|
*/
|
||||||
void LedController_SetLedBitNum(void * port, uint8_t pin, uint8_t bit);
|
void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the byte of data via led pins.
|
* Displays the byte of data via led pins.
|
||||||
*/
|
*/
|
||||||
void LedController_ShowByte(uint8_t byte);
|
void LedController_ShowByte(uint8_t byte);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the the first 4 bits of a byte.
|
* Displays the the first 4 bits of a byte.
|
||||||
*/
|
*/
|
||||||
void LedControler_ShowHalfByte(uint8_t byte);
|
void LedControler_ShowHalfByte(uint8_t byte);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears out the halfbyte led representation
|
* Clears out the halfbyte led representation
|
||||||
*/
|
*/
|
||||||
void LedControler_ClearHalfByte(void);
|
void LedControler_ClearHalfByte(void);
|
||||||
|
|
||||||
#endif //LEDCONTROLLER
|
#endif // LEDCONTROLLER
|
||||||
|
|
66
src/main.c
66
src/main.c
|
@ -15,36 +15,34 @@
|
||||||
// This can prevent issues with utils/delay.h library with the gcc toolchain
|
// This can prevent issues with utils/delay.h library with the gcc toolchain
|
||||||
#define __DELAY_BACKWARD_COMPATIBLE__
|
#define __DELAY_BACKWARD_COMPATIBLE__
|
||||||
|
|
||||||
#include "RegEdit.h"
|
|
||||||
#include "LedController.h"
|
#include "LedController.h"
|
||||||
|
#include "RegEdit.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include <avr/cpufunc.h> /* Required header file */
|
#include <avr/cpufunc.h> /* Required header file */
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
#define SW1PIN (1<<5)
|
#define SW1PIN (1 << 5)
|
||||||
#define SW2PIN (1<<4)
|
#define SW2PIN (1 << 4)
|
||||||
#define RELAYPIN (1<<1)
|
#define RELAYPIN (1 << 1)
|
||||||
#define RELAYREADINGPIN (1<<2) //It would be better to use PA7 so USART worked
|
#define RELAYREADINGPIN (1 << 2) // It would be better to use PA7 so USART worked
|
||||||
|
|
||||||
|
// Set the function pointer for the delay func
|
||||||
//Set the function pointer for the delay func
|
|
||||||
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
||||||
|
|
||||||
void SW1_Wait(void)
|
void SW1_Wait(void)
|
||||||
{
|
{
|
||||||
//poll the input.
|
// poll the input.
|
||||||
while(PORTA.IN & SW1PIN){}
|
while (PORTA.IN & SW1PIN) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SW2_Wait(void)
|
void SW2_Wait(void)
|
||||||
{
|
{
|
||||||
//poll the input.
|
// poll the input.
|
||||||
while(PORTA.IN & SW2PIN){}
|
while (PORTA.IN & SW2PIN) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Activate_Relay(void)
|
void Activate_Relay(void)
|
||||||
{
|
{
|
||||||
PORTA.OUT |= RELAYPIN;
|
PORTA.OUT |= RELAYPIN;
|
||||||
|
@ -55,18 +53,22 @@ void Deactivate_Relay(void)
|
||||||
PORTA.OUT &= ~RELAYPIN;
|
PORTA.OUT &= ~RELAYPIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WaitForRelayConnect(void)
|
void WaitForRelayConnect(void)
|
||||||
{
|
{
|
||||||
while(!(PORTB.IN & RELAYREADINGPIN)){;}
|
while (!(PORTB.IN & RELAYREADINGPIN))
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitForRelayDisconnect(void)
|
void WaitForRelayDisconnect(void)
|
||||||
{
|
{
|
||||||
while(PORTB.IN & RELAYREADINGPIN){;}
|
while (PORTB.IN & RELAYREADINGPIN)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
PORTA.DIR |= RELAYPIN;
|
PORTA.DIR |= RELAYPIN;
|
||||||
|
@ -74,30 +76,30 @@ int main(int argc, char **argv)
|
||||||
PORTA.DIR &= ~SW1PIN;
|
PORTA.DIR &= ~SW1PIN;
|
||||||
PORTA.DIR &= ~SW2PIN;
|
PORTA.DIR &= ~SW2PIN;
|
||||||
|
|
||||||
|
uint16_t make_time = 0;
|
||||||
uint16_t make_time = 0;
|
|
||||||
uint16_t break_time = 0;
|
uint16_t break_time = 0;
|
||||||
uint8_t temp = 0;
|
uint8_t temp = 0;
|
||||||
|
|
||||||
while(true) {
|
while (true)
|
||||||
|
{
|
||||||
SW1_Wait();
|
SW1_Wait();
|
||||||
Activate_Relay();
|
Activate_Relay();
|
||||||
|
|
||||||
Timer_Start();
|
Timer_Start();
|
||||||
WaitForRelayConnect();
|
WaitForRelayConnect();
|
||||||
Timer_Disable();
|
Timer_Disable();
|
||||||
|
|
||||||
make_time = Timer_GetOverflowCount();
|
make_time = Timer_GetOverflowCount();
|
||||||
|
|
||||||
//Output the Make time via LEDS
|
// Output the Make time via LEDS
|
||||||
//temp = (uint8_t)(make_time & 0x0F);
|
// temp = (uint8_t)(make_time & 0x0F);
|
||||||
temp = 0x01;
|
temp = 0x01;
|
||||||
LedControler_ShowHalfByte(temp);
|
LedControler_ShowHalfByte(temp);
|
||||||
|
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
LedControler_ClearHalfByte();
|
LedControler_ClearHalfByte();
|
||||||
|
|
||||||
//temp = (uint8_t)((make_time & 0xF0)>>4);
|
// temp = (uint8_t)((make_time & 0xF0)>>4);
|
||||||
temp = 0x02;
|
temp = 0x02;
|
||||||
LedControler_ShowHalfByte(temp);
|
LedControler_ShowHalfByte(temp);
|
||||||
|
|
||||||
|
@ -114,15 +116,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
break_time = Timer_GetOverflowCount();
|
break_time = Timer_GetOverflowCount();
|
||||||
|
|
||||||
//Output the Break time via LEDS
|
// Output the Break time via LEDS
|
||||||
//temp = (uint8_t)(break_time & 0x0F);
|
// temp = (uint8_t)(break_time & 0x0F);
|
||||||
temp = 0x04;
|
temp = 0x04;
|
||||||
LedControler_ShowHalfByte(temp);
|
LedControler_ShowHalfByte(temp);
|
||||||
|
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
LedControler_ClearHalfByte();
|
LedControler_ClearHalfByte();
|
||||||
|
|
||||||
//temp = (uint8_t)((break_time & 0xF0)>>4);
|
// temp = (uint8_t)((break_time & 0xF0)>>4);
|
||||||
temp = 0x08;
|
temp = 0x08;
|
||||||
LedControler_ShowHalfByte(temp);
|
LedControler_ShowHalfByte(temp);
|
||||||
|
|
||||||
|
@ -130,13 +132,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
LedControler_ClearHalfByte();
|
LedControler_ClearHalfByte();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
USART0_sendString(maketime_msg);
|
USART0_sendString(maketime_msg);
|
||||||
USART0_sendChar((uint8_t)(0xFF & make_time));
|
USART0_sendChar((uint8_t)(0xFF & make_time));
|
||||||
USART0_sendString(breaktime_msg);
|
USART0_sendString(breaktime_msg);
|
||||||
USART0_sendChar((uint8_t)(0xFF & break_time));
|
USART0_sendChar((uint8_t)(0xFF & break_time));
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,68 +13,65 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include <avr/io.h>
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
#define FCLK_PER 3333333UL
|
#define FCLK_PER 3333333UL
|
||||||
#define DIV8 0x3
|
#define DIV8 0x3
|
||||||
#define PERIOD_VALUE 40
|
#define PERIOD_VALUE 40
|
||||||
|
|
||||||
//These are expiremential found values that account for overhead
|
// These are expiremential found values that account for overhead
|
||||||
//for smaller durations.
|
// for smaller durations.
|
||||||
#define OVERHEAD_ONE 226
|
#define OVERHEAD_ONE 226
|
||||||
#define OVERHEAD_TWO 151
|
#define OVERHEAD_TWO 151
|
||||||
#define OVERHEAD_THREE 75
|
#define OVERHEAD_THREE 75
|
||||||
|
|
||||||
|
|
||||||
static uint16_t overflow_count = 0;
|
static uint16_t overflow_count = 0;
|
||||||
|
|
||||||
|
uint16_t Timer_GetOverflowCount(void)
|
||||||
uint16_t Timer_GetOverflowCount(void)
|
|
||||||
{
|
{
|
||||||
return overflow_count;
|
return overflow_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer_Start(void)
|
void Timer_Start(void)
|
||||||
{
|
{
|
||||||
//clear the overflow event count
|
// clear the overflow event count
|
||||||
overflow_count = 0;
|
overflow_count = 0;
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
//Enable the overflow Interrupt.
|
// Enable the overflow Interrupt.
|
||||||
TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;
|
TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm;
|
||||||
|
|
||||||
//set Normal mode.
|
// set Normal mode.
|
||||||
TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;
|
TCA0.SINGLE.CTRLB = TCA_SINGLE_WGMODE_NORMAL_gc;
|
||||||
|
|
||||||
//Disable event counting.
|
// Disable event counting.
|
||||||
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
|
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);
|
||||||
|
|
||||||
//Set the Period Value
|
// Set the Period Value
|
||||||
TCA0.SINGLE.PER = PERIOD_VALUE;
|
TCA0.SINGLE.PER = PERIOD_VALUE;
|
||||||
|
|
||||||
//set the Timer to divide FCLK_PER by 8.
|
// set the Timer to divide FCLK_PER by 8.
|
||||||
TCA0.SINGLE.CTRLA |= (DIV8<<1);
|
TCA0.SINGLE.CTRLA |= (DIV8 << 1);
|
||||||
|
|
||||||
//Enable the Timer
|
// Enable the Timer
|
||||||
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
|
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Timer_Disable(void)
|
void Timer_Disable(void)
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
TCA0.SINGLE.CTRLA &= ~(1<<0);
|
TCA0.SINGLE.CTRLA &= ~(1 << 0);
|
||||||
TCA0.SINGLE.CTRLESET |= ((0x3)<<2);
|
TCA0.SINGLE.CTRLESET |= ((0x3) << 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Triggered on the overflow of the timer A's counter.
|
// Triggered on the overflow of the timer A's counter.
|
||||||
ISR(TCA0_OVF_vect)
|
ISR(TCA0_OVF_vect)
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
//Increment the Overflow counter.
|
// Increment the Overflow counter.
|
||||||
overflow_count += 1;
|
overflow_count += 1;
|
||||||
|
|
||||||
// The interrupt flag has to be cleared manually
|
// The interrupt flag has to be cleared manually
|
||||||
|
|
|
@ -10,18 +10,17 @@
|
||||||
#ifndef TIMER
|
#ifndef TIMER
|
||||||
#define TIMER
|
#define TIMER
|
||||||
|
|
||||||
#include "stdbool.h"
|
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param a The first argument
|
* @param a The first argument
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void Timer_Start(void);
|
||||||
|
|
||||||
void Timer_Start(void);
|
void Timer_Disable(void);
|
||||||
|
|
||||||
void Timer_Disable(void);
|
|
||||||
|
|
||||||
uint16_t Timer_GetOverflowCount(void);
|
uint16_t Timer_GetOverflowCount(void);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __AVR_ATtiny404__
|
#ifndef __AVR_ATtiny404__
|
||||||
#define __AVR_ATtiny404__
|
#define __AVR_ATtiny404__
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,51 +13,48 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//These are technically correct, but the libc requires F_CPU for delay stuff
|
// These are technically correct, but the libc requires F_CPU for delay stuff
|
||||||
//that doesn't match the actual F_CPU because it uses the value after the
|
// that doesn't match the actual F_CPU because it uses the value after the
|
||||||
//clock is divided.
|
// clock is divided.
|
||||||
|
|
||||||
//#define F_CPU 3333333UL
|
|
||||||
//#define F_PER F_CPU / 6
|
|
||||||
|
|
||||||
|
// #define F_CPU 3333333UL
|
||||||
|
// #define F_PER F_CPU / 6
|
||||||
|
|
||||||
#define F_PER 3333333UL
|
#define F_PER 3333333UL
|
||||||
#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_PER * 64 / (16 * (float)BAUD_RATE)) + 0.5)
|
#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_PER * 64 / (16 * (float)BAUD_RATE)) + 0.5)
|
||||||
|
|
||||||
|
// RX PIN6, TX PIN7
|
||||||
//RX PIN6, TX PIN7
|
// ALT: RX PIN12 TX PIN11
|
||||||
//ALT: RX PIN12 TX PIN11
|
|
||||||
void USART0_Init(void)
|
void USART0_Init(void)
|
||||||
{
|
{
|
||||||
//Config TxD as output, and rx as input?
|
// Config TxD as output, and rx as input?
|
||||||
PORTB.DIR &= ~(1<<3);
|
PORTB.DIR &= ~(1 << 3);
|
||||||
PORTB.DIR |= (1<<2);
|
PORTB.DIR |= (1 << 2);
|
||||||
|
|
||||||
//It says to set the TX pin high?
|
// It says to set the TX pin high?
|
||||||
//PORTB.OUT |= (1<<2);
|
// PORTB.OUT |= (1<<2);
|
||||||
|
|
||||||
//set buad rate.
|
// set buad rate.
|
||||||
USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
|
USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
|
||||||
//USART0.BAUD = 1388;
|
// USART0.BAUD = 1388;
|
||||||
|
|
||||||
//set the frame format.
|
// set the frame format.
|
||||||
USART0.CTRLC = 0x3; //setting 8-bit mode.
|
USART0.CTRLC = 0x3; // setting 8-bit mode.
|
||||||
|
|
||||||
//Enable transmitter and receiver (USARTn.CTRLB)
|
// Enable transmitter and receiver (USARTn.CTRLB)
|
||||||
//USART0.CTRLB |= (1<<7)|(1<<6);
|
// USART0.CTRLB |= (1<<7)|(1<<6);
|
||||||
USART0.CTRLB |= USART_TXEN_bm;
|
USART0.CTRLB |= USART_TXEN_bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART0_Alt_Init(void)
|
void USART0_Alt_Init(void)
|
||||||
{
|
{
|
||||||
|
// setup Alternate pints on PA1 and PA2
|
||||||
//setup Alternate pints on PA1 and PA2
|
|
||||||
PORTMUX.CTRLB |= PORTMUX_USART0_ALTERNATE_gc;
|
PORTMUX.CTRLB |= PORTMUX_USART0_ALTERNATE_gc;
|
||||||
PORTA.DIR |= (1<<1);
|
PORTA.DIR |= (1 << 1);
|
||||||
PORTA.DIR &= ~(1<<2);
|
PORTA.DIR &= ~(1 << 2);
|
||||||
|
|
||||||
//It says to set the TX pin high?
|
// It says to set the TX pin high?
|
||||||
//PORTA.OUT |= (1<<11);
|
// PORTA.OUT |= (1<<11);
|
||||||
|
|
||||||
// set buad rate.
|
// set buad rate.
|
||||||
USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
|
USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);
|
||||||
|
|
|
@ -15,9 +15,8 @@
|
||||||
*/
|
*/
|
||||||
void USART0_Init(void);
|
void USART0_Init(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the USART0 peripheral on Alternate pins.
|
* @brief Initializes the USART0 peripheral on Alternate pins.
|
||||||
*/
|
*/
|
||||||
void USART0_Alt_Init(void);
|
void USART0_Alt_Init(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue