#include "LCDMain.h" #include "lcd.h" #include "stm32f10x_it.h" #include "stdio.h" #define CAPS_LOCK_CODE 0x58 // Macro for Caps Lock scan code #define LOWER 0 // Macro for lower case keyboard #define UPPER 1 // Macro for upper case keyboard EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; static int ch; static int cho; unsigned char Mx=0; // Define for counter loop unsigned char MODE=0; static unsigned int KeyCode=0; static unsigned int xpos=0, ypos=146; char char_case =LOWER; // Variable for status character case(lower or upper) const unsigned char _ascii_key[128] = // Table for decode { 0 // 0x00 , 0 // 0x01 , 0 // 0x02 , 0 // 0x03 , 0 // 0x04 , 0 // 0x05 , 0 // 0x06 , 0 // 0x07 , 0 // 0x08 , 0 // 0x09 , 0 // 0x0A , 0 // 0x0B , 0 // 0x0C , 11 // 0x0D , 0 // 0x0E , 0 // 0x0F , 0 // 0x10 , 0 // 0x11 , 0 // 0x12 , 0 // 0x13 , 0 // 0x14 , 'q' // 0x15 , '!' // 0x16 , 0 // 0x17 , 0 // 0x18 , 0 // 0x19 , 'z' // 0x1A , 's' // 0x1B , 'a' // 0x1C , 'w' // 0x1D , '@' // 0x1E , 0 // 0x1F , 0 // 0x20 , 'c' // 0x21 , 'x' // 0x22 , 'd' // 0x23 , 'e' // 0x24 , '$' // 0x25 , '#' // 0x26 , 0 // 0x27 , 0 // 0x28 , 32 // 0x29 , 'v' // 0x2A , 'f' // 0x2B , 't' // 0x2C , 'r' // 0x2D , '%' // 0x2E , 0 // 0x2F , 0 // 0x30 , 'n' // 0x31 , 'b' // 0x32 , 'h' // 0x33 , 'g' // 0x34 , 'y' // 0x35 , '^' // 0x36 , 0 // 0x37 , 0 // 0x38 , 0 // 0x39 , 'm' // 0x3A , 'j' // 0x3B , 'u' // 0x3C , '&' // 0x3D , '*' // 0x3E , 0 // 0x3F , 0 // 0x40 , 44 // 0x41 , 'k' // 0x42 , 'i' // 0x43 , 'o' // 0x44 , ')' // 0x45 , '(' // 0x46 , 0 // 0x47 , 0 // 0x48 , '.' // 0x49 , '/' // 0x4A , 'l' // 0x4B , ';' // 0x4C , 'p' // 0x4D , '-' // 0x4E , 0 // 0x4F , 0 // 0x50 , 0 // 0x51 , 39 // 0x52 , 0 // 0x53 , 0 // 0x54 , '=' // 0x55 , 0 // 0x56 , 0 // 0x57 , 0 // 0x58 , 0 // 0x59 , 13 // 0x5A , ']' // 0x5B , 0 // 0x5C , 92 // 0x5D , 0 // 0x5E , 0 // 0x5F , 0 // 0x60 , 0 // 0x61 , 0 // 0x62 , 0 // 0x63 , 0 // 0x64 , 0 // 0x65 , 8 // 0x66 , 0 // 0x67 , 0 // 0x68 , '1' // 0x69 , 0 // 0x6A , '4' // 0x6B , '7' // 0x6C , 0 // 0x6D , 0 // 0x6E , 0 // 0x6F , '0' // 0x70 , '.' // 0x71 , '2' // 0x72 , '5' // 0x73 , '6' // 0x74 , '8' // 0x75 , 27 // 0x76 , 0 // 0x77 , 0 // 0x78 , '+' // 0x79 , '3' // 0x7A , '-' // 0x7B , '*' // 0x7C , '9' // 0x7D , 0 // 0x7E , 0 // 0x7F }; void RCC_Configuration (void); void GPIO_Configuration (void); void NVIC_Configuration (void); void EXTI_Configuration (void); unsigned char kb_getchar(void); unsigned char ident(void); ErrorStatus HSEStartUpStatus; int main (void) { #ifdef DEBUG debug (); #endif /* * System Clocks Configuration */ RCC_Configuration (); /* * NVIC Configuration */ NVIC_Configuration (); /* * GPIO ports pins Configuration */ GPIO_Configuration (); EXTI_Configuration (); LCD_Init (); /* switching backlight on and off while running this in debugger step-by-step */ LCD_SetBackLightOn (); LCD_BackLightChange (); //LCD_Handler(); LCD_SetBackLightOff (); LCD_BackLightChange (); //LCD_Handler(); LCD_SetBackLightOn (); LCD_BackLightChange (); //LCD_Handler(); LCD_FillRect (0,0,200,300,RGB_GREEN); //LCD_DisplayChar( 10, 10, 65, RGB_RED, RGB_YELLOW, 1 ); //LCD_DisplayChar( 30, 10, 66, RGB_RED, RGB_YELLOW, 1 ); //LCD_DisplayChar( 50, 10, 67, RGB_RED, RGB_YELLOW, 1 ); // switch off LEDs GPIO_WriteBit (GPIOE, GPIO_Pin_LED0, Bit_SET); GPIO_WriteBit (GPIOE, GPIO_Pin_LED1, Bit_RESET); GPIO_WriteBit (GPIOE, GPIO_Pin_LED0, Bit_SET); GPIO_WriteBit (GPIOE, GPIO_Pin_LED1, Bit_SET); while (1) {; } } void EXTI_Configuration (void) { /* Connect EXTI Line7 to PB.07 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource7); /* Configure EXTI Line9 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line7; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Connect EXTI Line15 to PB.15 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource15); /* Configure EXTI Line9 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); } void RCC_Configuration (void) { /* * RCC system reset(for debug purpose) */ RCC_DeInit (); /* * Enable HSE */ RCC_HSEConfig (RCC_HSE_ON); /* * Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp (); if (HSEStartUpStatus == SUCCESS) { // / Enable Prefetch Buffer FLASH_PrefetchBufferCmd (FLASH_PrefetchBuffer_Enable); /* * HCLK = SYSCLK */ RCC_HCLKConfig (RCC_SYSCLK_Div1); /* * PCLK2 = HCLK */ RCC_PCLK2Config (RCC_HCLK_Div1); /* * PCLK1 = HCLK */ RCC_PCLK1Config (RCC_HCLK_Div1); /* * Select HSE as system clock source */ RCC_SYSCLKConfig (RCC_SYSCLKSource_HSE); /* * Wait till HSE is used as system clock source */ while (RCC_GetSYSCLKSource () != 0x04) { } } /* * GPIOA and GPIO_LED clock enable and GPIOD for CAN */ RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIO_LED | RCC_APB2Periph_AFIO, ENABLE); return; } void GPIO_Configuration (void) { GPIO_InitTypeDef GPIO_InitStructure; /* * Configure GPIOE pin0 and pin1 as Output push-pull (LEDs) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init (GPIOE, &GPIO_InitStructure); /* Configure PB7 as input floating (EXTI Line7) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure PB15 as input floating (EXTI Line15) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); // return; } void NVIC_Configuration (void) { //NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* * Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable (NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* * Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable (NVIC_VectTab_FLASH, 0x0); #endif NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // return; } //------------------------------------------------------------------------------------------------// //---------------------------------- Function get character from keyboard ------------------------// //------------------------------------------------------------------------------------------------// unsigned char kb_getchar(void) { static unsigned char temp=0,bk=0; unsigned char result; if(Mx>9) { Mx=0; MODE = 0; temp = KeyCode; // Keep code detect if(bk==2) // Not keep code for 0xF0,0xE0,0xE1 sequent bk =0; if(bk==1) // Not keep code for 0xF0,0xE0,0xE1 sequent bk =2; if(KeyCode==0xF0 || KeyCode==0xE0) // Check break code and none key support bk=1; // Start break code sequent KeyCode = 0; // Clear old code if((temp !=0xF0 || temp !=0xE0 || temp !=0xE1) && bk==0) // Check code support? { if(temp == CAPS_LOCK_CODE) // Check Caps Lock mode key push? char_case ^=1; // Toggle status Caps Lock mode if(char_case==UPPER) // Check Upper case for character 'A'-'Z' result = toupper(_ascii_key[temp]); // Result 'A'-'Z' else result = _ascii_key[temp]; // Result 'a'-'z' return(result); // Return result } else return(0); } else return(0); } unsigned char ident(void) { ch= kb_getchar(); // diese Funktion liefert das eingegebene Ziffern int l; for(l=0;l<5;l++)// ich habe hier for schleife aufgebaut, bis 4x { if(ch != 0) { xpos+=7; if (xpos>121) { xpos = 0; ypos = ypos - 14; } GPIO_WriteBit (GPIOE, GPIO_Pin_LED0, Bit_RESET); GPIO_WriteBit (GPIOE, GPIO_Pin_LED1,Bit_RESET); LCD_DisplayChar( xpos, ypos, ch, RGB_RED, RGB_YELLOW, 1); if (l==4) { LCD_DisplayChar( xpos, ypos, 83, RGB_RED, RGB_YELLOW, 1); LCD_DisplayChar( xpos, ypos, 79, RGB_RED, RGB_YELLOW, 1); LCD_DisplayChar( xpos, ypos, 82, RGB_RED, RGB_YELLOW, 1); LCD_DisplayChar( xpos, ypos, 82, RGB_RED, RGB_YELLOW, 1); LCD_DisplayChar( xpos, ypos, 89, RGB_RED, RGB_YELLOW, 1); } } } } //------------------------------------------------------------------------------------------------// /******************************************************************************* * Function Name : EXTI15_10_IRQHandler * Description : This function handles External lines 15 to 10 interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void EXTI15_10_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line15) != RESET) { /* Toggle PE1 pin */ GPIO_WriteBit(GPIOE, GPIO_Pin_1, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_0)))); if(MODE) // Start Bit has been received { KeyCode = KeyCode >> 1; // Shift "old" data bits to right 1 time if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7)) // If "1" has been received KeyCode = KeyCode | 0x8000; // set MSB to 1 Mx++; // Bitcounter +1 if(Mx>9) // 10 Bits reveived { KeyCode = KeyCode>>6; // Shift right 6 times (10+6=16) KeyCode &= 0x00FF; // Mask keep only Low 8 Bit MODE = 0; ident(); // Set "Ready for new transfer" // ch = kb_getchar(); //if(ch != 0) //{ // xpos+=7; //if (xpos>121) // { xpos = 0; // ypos = ypos - 14; // } // GPIO_WriteBit (GPIOE, GPIO_Pin_LED0, Bit_RESET); // GPIO_WriteBit (GPIOE, GPIO_Pin_LED1, Bit_RESET); // LCD_DisplayChar( xpos, ypos, ch, RGB_RED, RGB_YELLOW, 1 ); //} } } else // If begin of new transfer { if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7)==0) // Check start bit true? { MODE = 1; // Start of transfer received } } /* Clear the EXTI line 15 pending bit */ EXTI_ClearITPendingBit(EXTI_Line15); } } #ifdef DEBUG /******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert error has occurred. * Input : - file: pointer to the source file name * - line: assert error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed (u8 * file, u32 line) { // User can add his own implementation to report the file name and // line number, // ex: printf("Wrong parameters value: file %s on line %d\r\n", file, // line) // Infinite loop while (1) { } } #endif /* from main.c from CircleOS ... */ int fct_dummy() {;}