Escolar Documentos
Profissional Documentos
Cultura Documentos
Pada praktikum kali ini kami melakukan pembuatan program dan menggunakan bantuan software
visual studio untuk membuat tampilan kotak dialog pada PC. Dalam percobaan kali ini adalah
terkait dengan komunikasi serial 2 arah dimana komunikasi dilakukan dari PC ke ARM, begitupun
sebaliknya dari ARM ke PC. Dalam melakukan komunikasi serial dari ARM ke PC, akan
diimplementasikan dengan pengaktifan dan pengnonaktifan LED pada modul ARM. Dan untuk
komunikasi serial dari PC ke ARM adalah dengan pembacaan sensor tegangan dengan potensio
yang nantinya akan tampil dalam PC. Untuk program yang digunakan adalah
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "lcd_character.h"
#include "stdlib.h"
uint8_t rx_data,datasend[]={"OK\n"}; //
char buffer[RX_BUFFER_SIZE];
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
UART_HandleTypeDef huart1;
void SystemClock_Config(void);
int main(void)
char simpan[20];
//int r,s,t,x,a,b,c,y,u;
int a;
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
__HAL_UART_ENABLE_IT(&huart1, UART_IT_TC);
HAL_UART_Receive_IT(&huart1,&rx_data,1);
lcd_init();
/* Infinite loop */
while (1)
a=Nilai_ADC[1];
//lcd_gotoxy(0,0);
//sprintf(simpan,"%4d\r",a);
HAL_Delay (10);
//lcd_puts(simpan);
char buffer[5];
add_dev=1; lcd_gotoxy(0,1);
lcd_data(rx_buffer[0]); lcd_data(rx_buffer[1]);
lcd_data(rx_buffer[2]); lcd_data(rx_buffer[3]);
lcd_data(rx_buffer[4]); lcd_data(rx_buffer[5]);
lcd_data(rx_buffer[6]); lcd_data(rx_buffer[7]);
lcd_data(rx_buffer[8]); lcd_data(rx_buffer[9]);
lcd_data(rx_buffer[10]); lcd_data(rx_buffer[11]);
{ sprintf(buffer,"%c%c",rx_buffer[2],rx_buffer[3]);
add_data=atoi(buffer);
if (add_data==add_dev)
{ sprintf(buffer,"%c%c",rx_buffer[4],rx_buffer[5]);
ch=atoi(buffer)
if(ch==0)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_0,GPIO_PIN_SET);
else if (ch==1)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_1,GPIO_PIN_SET);
else if (ch==2)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_SET);
else if (ch==3)
{
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
else if (ch==4)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
else if (ch==5)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
else if (ch==6)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
else if (ch==7)
if(rx_buffer[6]=='1') HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);
//rx_buffer[7]=0;
else if (rx_buffer[0]=='*'&&rx_buffer[6]=='#' )
sprintf(buffer,"%c%c",rx_buffer[2],rx_buffer[3]);
add_data=atoi(buffer);
if (add_data==add_dev)
sprintf(buffer,"%c%c",rx_buffer[4],rx_buffer[5]);
ch=atoi(buffer);
if(ch==0)
sprintf(simpan,"0100%4d",a);
HAL_UART_Transmit_IT(&huart1, (uint8_t *)simpan,8);
lcd_gotoxy(8,0);
HAL_Delay (10);
lcd_puts(simpan); }
else if (ch==1)
sprintf(simpan,"0101%4d",a);
lcd_gotoxy(8,0);
HAL_Delay (10);
lcd_puts(simpan);
else if (ch==2)
sprintf(simpan,"Val:%4d",a);
lcd_gotoxy(0,0);
HAL_Delay (10);
lcd_puts(simpan);
else if (ch==3)
sprintf(simpan,"0103%4d",a);
lcd_gotoxy(8,0);
HAL_Delay (10);
lcd_puts(simpan);
rx_buffer[6]=' ';
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
HAL_UART_Receive_IT(&huart1,&rx_data,1);
if(rx_data=='*'||rx_index>RX_BUFFER_SIZE)
{rx_index=0;
rx_buffer [rx_index]=rx_data;
rx_index++;