“藍橋杯”使用的CT117E嵌入式。
0.png (44.46 KB, 下載次數: 22)
下載附件
2018-7-6 04:12 上傳
單片機源程序如下:
- /******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
- * File Name : main.c
- * Author : MCD Application Team
- * Version : V3.0.0
- * Date : 04/06/2009
- * Description : Virtual Com Port Demo main file
- ********************************************************************************
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
- * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
- * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
- * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
- * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "stdio.h"
- #include "main.h"
- #include "lcd.h"
- #include "i2c.h"
- #include "adc_single.h"
- #include "usart.h"
- #include "stdlib.h"
- #define COL(X) (319-(X)*16+16)
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- static __IO uint32_t TimingDelay;
- extern USART_TypeDef* USARTx;
- extern vu16 dummy; //LCD型號定位
- void Delay_Ms(__IO uint32_t nTime);
- /* Extern variables ----------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /**
- * @}
- */
- void RCC_Configuration(void)
- {
- /* GPIOA Periph clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
- }
- /**
- * @}
- */
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
- GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 |
- GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 ;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- //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
- //
- // /* Configure one bit for preemption priority */
- // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- //
- // /* Enable the EXTI9_5 Interrupt */
- // NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- //}
- //void delay()
- //{
- // unsigned int i,j;
- // for (i = 0;i<0xffff;++i)
- // for(j=0;j<0x7f;++j);
- //}
- /*******************************************************************************
- * Function Name : main.
- * Description : Main routine.
- * Input : None.
- * Output : None.
- * Return : None.
- *******************************************************************************/
- int main(void)
- {
- int n;
- // unsigned short Pin;
- unsigned char lcd_type[4]; //保存LCD型號的數組
- unsigned char bai,shi,ge;
- float ad_value;
- int toggle;
- RCC_Configuration();
- GPIO_Configuration();
- GPIO_PinRemapConfig ( GPIO_Remap_SWJ_NoJTRST ,ENABLE);
- // NVIC_Configuration();
- i2c_init();
- adc_init();
- usart_init();
- if (SysTick_Config(SystemCoreClock / 1000))
- {
- /* Capture error */
- while (1);
- }
- n=x24c02_read(0xff);
- Delay_Ms(10);
- ++n;
- x24c02_write(0xff,n);
-
- bai = n/100;
- shi = (n-bai*100) / 10; //ADC數值的十號準備情況參考這些數值 Capture error
- ge = n % 10; //ADC數值的個位準備情況參考這些數值 Capture error準備情況
- STM3210B_LCD_Init();
- LCD_Clear(Blue);
- LCD_SetBackColor(Red);
- /* Set the LCD Text Color */
- LCD_SetTextColor(Grey);
- lcd_type[0] = (dummy>>12)+'0';
- lcd_type[1] = ((dummy&0x0f00)>>8)+'0';
- lcd_type[2] = ((dummy&0x00f0)>>4)+'0';
- lcd_type[3] = (dummy&0x000f)+ '0';
-
- LCD_DisplayStringLine(Line0, " ");
- LCD_DisplayStringLine(Line1, " Welcome to ");
- LCD_DisplayStringLine(Line2, " ");
- LCD_SetBackColor(Green);
- // LCD_SetTextColor(Grey);
- LCD_DisplayStringLine(Line4, " GXCT ");
- LCD_DisplayStringLine(Line3, " ");
- LCD_DisplayStringLine(Line5, " ");
- LCD_SetBackColor(Blue);
- // LCD_SetTextColor(Grey);
- LCD_DisplayStringLine(Line6, " ");
- LCD_DisplayStringLine(Line7, " LCD TYPE: ");
- LCD_SetTextColor(Yellow);
- LCD_DisplayChar(Line7,COL(13),lcd_type[0]);
- LCD_DisplayChar(Line7,COL(14),lcd_type[1]);
- LCD_DisplayChar(Line7,COL(15),lcd_type[2]);
- LCD_DisplayChar(Line7,COL(16),lcd_type[3]);
- LCD_DisplayStringLine(Line8, " ");
- LCD_DisplayStringLine(Line9, " ");
- LCD_SetTextColor(Green);
- LCD_DisplayChar(Line9,COL(19),ge+'0');
- if ( n > 9 ) LCD_DisplayChar(Line9,COL(18),shi+'0');
- if ( n > 99 ) LCD_DisplayChar(Line9,COL(17),bai+'0');
- LCD_SetTextColor(Grey);
- GPIO_Write(GPIOC,0xffff);
- GPIO_SetBits(GPIOD,GPIO_Pin_2);
- GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- while(1) {
- if ( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == RESET ) {
- // Pin=GPIO_Pin_8 | GPIO_Pin_12;
- GPIO_Write(GPIOC,0xfcff);
- GPIO_SetBits(GPIOD,GPIO_Pin_2);
- GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- } else if ( GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8) == RESET ) {
- // Pin=GPIO_Pin_9 | GPIO_Pin_13;
- GPIO_Write(GPIOC,0xf3ff);
- GPIO_SetBits(GPIOD,GPIO_Pin_2);
- GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- } else if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == RESET ) {
- // Pin=GPIO_Pin_10 | GPIO_Pin_14;
- GPIO_Write(GPIOC,0xcfff);
- GPIO_SetBits(GPIOD,GPIO_Pin_2);
- GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- } else if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2) == RESET ) {
- // Pin=GPIO_Pin_11 | GPIO_Pin_15;
- GPIO_Write(GPIOC,0x3fff);
- GPIO_SetBits(GPIOD,GPIO_Pin_2);
- GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- }
- if ( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2) == RESET ) {
- GPIO_ResetBits(GPIOB,GPIO_Pin_4);
- } else {
- GPIO_SetBits(GPIOB,GPIO_Pin_4);
- }
- // Pin=GPIO_Pin_8;
- // for ( i=0;i<8;++i) {
- // GPIO_SetBits(GPIOD,GPIO_Pin_2);
- // GPIO_Write(GPIOC,Pin);
- // GPIO_ResetBits(GPIOD,GPIO_Pin_2);
- // delay();
- // Pin<<=1;
- // }
- ad_value= adc_read();
- ge=ad_value;
- shi=(int)(ad_value*10)%10;
- bai= (int)(ad_value*100)%10;
- LCD_SetTextColor(Red);
- LCD_DisplayChar(Line9,COL(2),ge+'0');
- LCD_DisplayChar(Line9,COL(3),'.');
- LCD_DisplayChar(Line9,COL(4),shi+'0');
- LCD_DisplayChar(Line9,COL(5),bai+'0');
- USARTx = USART2;
- if( (n=USART_getch()) != -1 ) {
- LCD_DisplayChar(Line8,COL(12),n);
- printf("USART2 Echo: %f\r\n",rand()*25./RAND_MAX);
-
- // printf("USART2 Echo: %c\r\n",n);
- }
- USARTx = USART1;
- if( (n=USART_getch()) != -1 ) {
- LCD_DisplayChar(Line8,COL(9),n);
- printf("USART1 Echo: %c\r\n",n);
- }
- toggle = ! toggle;
- if ( toggle ) {
- GPIO_SetBits(GPIOA,GPIO_Pin_1);
- GPIO_SetBits(GPIOA,GPIO_Pin_4);
- GPIO_SetBits(GPIOA,GPIO_Pin_5);
- GPIO_SetBits(GPIOA,GPIO_Pin_6);
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- }else{
- GPIO_ResetBits(GPIOA,GPIO_Pin_1);
- GPIO_ResetBits(GPIOA,GPIO_Pin_4);
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6);
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- }
- }
- }
- void Delay_Ms(__IO uint32_t nTime)
- {
- TimingDelay = nTime;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
CT117E-測試程序.zip
(2.52 MB, 下載次數: 15)
2018-7-5 19:04 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|