1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| *
* Before you start, select your target, on the right of the "Load" button
*
* @author julien terrier
* @email
* @ide Keil uVision 5
* @packs STM32F4xx Keil packs version 2.2.0 or greater required
* @stdperiph STM32F4xx Standard peripheral drivers version 1.4.0 or greater required
*/
/* Include core modules */
#include "stm32f4xx.h"
/* Include my libraries here */
#include "defines.h"
#include "tm_stm32f4_delay.h"
#include "tm_stm32f4_usart.h"
#include <stdio.h>
#include <string.h>
#include "GLCD.h"
/* Pivate function*/
void compare (char *c);
#define __FI 0 /* Font index 6x8 */
#if (__FI == 1) /* Font index 16x24 */
#define __FONT_WIDTH 16
#define __FONT_HEIGHT 24
#else /* Font index 6x8 */
#define __FONT_WIDTH 6
#define __FONT_HEIGHT 8
#endif
uint8_t continuer = 1;
int main(void)
{
uint8_t i, a, c = 0, j = 0;
uint8_t ligne = 1, colonne = 0;
char chaine1[20] = {""};
/* Initialize system */
SystemInit();
/* Initialize delay */
TM_DELAY_Init();
GLCD_Initialize(); /* GLCD Initialization */
GLCD_Clear(White); /* Clear graphical LCD display */
GLCD_SetTextColor(Black);
/* Initialize USART1 at 9600 baud, TX: PB6, RX: PB7 */
TM_USART_Init(USART1, TM_USART_PinsPack_2, 9600);
while (continuer)
{
/* Get character from internal buffer */
c = TM_USART_Getc(USART1);
if(32 <= c && c <= 126) /* caractères choisis en provenance du PC */
{
GLCD_DisplayChar(ligne, colonne, __FI, c);
colonne += 1;
if(colonne >= 40)
{
ligne += 1;
colonne = 0;
}
chaine1[j] = c;
j++;
/* écho vers le terminal */
TM_USART_Putc(USART1, c);
}
switch (c)
{
case 8:
GLCD_DisplayChar(ligne, colonne, __FI, 0);
colonne -= 1;
if(colonne == 0)
ligne-=1;
if(ligne == 0)
ligne = 0;
TM_USART_Putc(USART1, c);
break;
/* code ASCII retour chariot */
case 10:
compare(chaine1);
j = 0;
for (a = 0 ; a < 20 ; a++)
chaine1[a] = 0;
ligne += 1;
colonne = 0;
GLCD_DisplayChar(ligne, colonne, __FI, 0);
while (TM_USART_BufferEmpty (USART1) != 0)
{
TM_USART_ClearBuffer(USART1);
Delayms(1000);
}
/* écho vers le terminal */
TM_USART_Putc(USART1, c);
break;
/* code ASCII retour chariot */
case 13:
ligne += 1;
colonne = 0;
GLCD_DisplayChar(ligne, colonne, __FI, 0);
/* écho vers le terminal */
TM_USART_Putc(USART1, c);
break;
}
switch(ligne)
{
case 40:
for(i=5; i > 0 ; i--)
/* Rafraichissement de l'ecran on efface la ligne 1 a 5 */
GLCD_ClearLn (i, __FI);
ligne = 0;
break;
case 5:
for(i=10; i > 5 ; i--)
/* Rafraichissement de l'ecran, on efface la ligne 6 a 10 */
GLCD_ClearLn (i, __FI);
ligne = 5;
break;
case 10:
for(i=15; i > 10 ; i--)
/* Rafraichissement de l'ecran, on efface la ligne 11 a 15 */
GLCD_ClearLn (i, __FI);
ligne = 10;
break;
case 15:
for(i=20; i > 15 ; i--)
/* Rafraichissement de l'ecran, on efface la ligne 16 a 20 */
GLCD_ClearLn (i, __FI);
ligne = 15;
break;
case 20:
for(i=25; i > 20 ; i--)
/* Rafraichissement de l'ecran on efface la ligne 21 a 25 */
GLCD_ClearLn (i, __FI);
ligne = 20;
break;
case 25:
for(i=30; i > 25 ; i--)
/* Rafraichissement de l'ecran, on efface la ligne 26 a 30 */
GLCD_ClearLn (i, __FI);
ligne = 25;
break;
case 30:
for(i=35; i > 30 ; i--)
/* Rafraichissement de l'ecran on efface la ligne 31 a 35 */
GLCD_ClearLn (i, __FI);
ligne = 30;
break;
case 35:
for(i=40; i > 35 ; i--)
/* Rafraichissement de l'ecran on efface la ligne 36 a 40 */
GLCD_ClearLn (i, __FI);
ligne = 35;
break;
}
}
}
void compare (char *chaine1)
{
char chaine3[20] = "--> LPT> 139 LPT>";
Delayms(10);
if (strcmp(chaine3, chaine1) == 0) // Si chaînes identiques
{
continuer = 0;
}
} |
Partager