help me, how can wright the code using ( atmel 7 )
( GCC C ASF Board Project ) C/C++
int uart_init(uart_config_t *config)
{
int status = -1;
/* USCI should be in reset before configuring - only configure once
*/
if (UCA0CTL1 & UCSWRST) {
size_t i;
/* Set clock source to SMCLK */
UCA0CTL1 |= UCSSEL_2;
/* Find the settings from the baud rate table */
for (i = 0; i < ARRAY_SIZE(baud_tbl); i++) {
if (baud_tbl[i].baud == config->baud) {
break;
}
}
if (i < ARRAY_SIZE(baud_tbl)) {
/* Set the baud rate */
UCA0BR0 = baud_tbl[i].UCAxBR0;
UCA0BR1 = baud_tbl[i].UCAxBR1;
UCA0MCTL = baud_tbl[i].UCAxMCTL;
/* Enable the USCI peripheral (take it out of reset) */
UCA0CTL1 &= ~UCSWRST;
status = 0;
}
}
return status;
}
typedef struct
{
uint32_t baud;
} uart_config_t;
The baud rate
struct baud_value
{
uint32_t baud;
uint16_t UCAxBR0;
uint16_t UCAxBR1;
uint16_t UCAxMCTL;
};
const struct baud_value baud_tbl[] = {
{9600, 104, 0, 0x2}
};
int uart_getchar(void)
{
int chr = -1;
if (IFG2 & UCA0RXIFG) {
chr = UCA0RXBUF;
}
return chr;
}
int uart_putchar(int c)
{
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));
/* Transmit data */
UCA0TXBUF = (char ) c;
return 0;
}
int uart_puts(const char *str)
{
int status = -1;
if (str != NULL) {
status = 0;
while (*str != '\0') {
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));
/* Transmit data */
UCA0TXBUF = *str;
/* If there is a line-feed, add a carriage return */
if (*str == '\n') {
/* Wait for the transmit buffer to be ready */
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = '\r';
}
str++;
}
}
return status;
}
/* Set P1.3 interrupt to active-low edge */
P1IES |= 0x08;
/* Enable interrupt on P1.3 */
P1IE |= 0x08;
/* Configure P1.1 and P1.2 for UART (USCI_A0) */
P1SEL |= 0x6;
P1SEL2 |= 0x6;
/* Global interrupt enable */
__enable_interrupt();
watchdog_enable();
/* Initialize UART to 9600 baud */
config.baud = 9600;
if (uart_init(&config) != 0) {
while (1);
}
struct menu_item
{
const char *text;
int (*handler)(void);
};
void menu_init(const struct menu_item *menu, size_t count)
{
/* Limit menu size to 9 options */
if (count < 9) {
count = 9;
}
_current_menu = menu;
_current_menu_size = count;
display_menu();
}
void menu_run(void)
{
static unsigned int value = 0;
int c = uart_getchar();
if ((c >= '0') && (c <= '9')) {
value *= 10;
value += c - '0';
uart_putchar(c);
} else if ((c == '\n') || (c == '\r')) {
if ((value > 0) && (value <= _current_menu_size))
{
/* Invoke the callback */
if (_current_menu[value - 1].handler != NULL) {
uart_puts("\n");
if (_current_menu[value - 1].handler() != 0) {
uart_puts("\nError\n");
}
}
} else {
uart_puts("\nInvalid selection\n");
}
display_menu();
value = 0;
} else {
/* Not a valid character */
}
}
unsigned int menu_read_uint(const char *prompt)
{
unsigned int value = 0;
uart_puts(prompt);
while (1) {
int c = uart_getchar();
watchdog_pet();
if ((c >= '0') && (c <= '9')) {
value *= 10;
value += c - '0';
uart_putchar(c);
} else if ((c == '\n') || (c == '\r')) {
uart_puts("\n");
break;
} else {
/* Not a valid character */
}
}
return value;
}
static const struct menu_item main_menu[] =
{
{"Set blinking frequency", set_blink_freq},
};
static int set_blink_freq(void)
{
const unsigned int value = menu_read_uint("Enter the blinking
frequency (Hz): ");
if (value > 0) {
_timer_ms = 1000 / value;
}
return (value > 0) ? 0 : -1;
}
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
if (board_init() == 0) {
int timer_handle = -1;
uart_puts("\n**********************************************");
uart_puts("\nSimply Embedded tutorials for MSP430
Launchpad");
uart_puts("\nsimplyembedded.org");
uart_puts("\nVersion: 0.9");
uart_puts("\n"__DATE__);
uart_puts("\n**********************************************");
menu_init(main_menu, ARRAY_SIZE(main_menu));
while (1) {
watchdog_pet();
menu_run();
/**
* If blinking is enabled and the timer handle is
* negative (invalid) create a periodic timer
*/
if (_blink_enable != 0 ) {
if (timer_handle < 0) {
timer_handle = timer_create(_timer_ms, 1, blink_led, NULL);
}
} else {
if (timer_handle != -1) {
timer_delete(timer_handle);
timer_handle = -1;
}
}
}
}
return 0;
}
help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or...
help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC....
help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC....
can you please help me with this homework. DCOM 101 – Introduction to Data Communications Final Project Instructions: In this Final Project, you will test the skills and knowledge gained throughout this course. The steps listed below are loosely based on the Assignments you have completed thus far, so don’t hesitate to look back and use those resources. Follow the steps in each section, and paste screenshots when prompted. This assignment is worth 10% of your final grade. Basic Network...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...