標題: 基于STC15F單片機的太陽能版追光系統(tǒng)程序與原理圖PCB [打印本頁]

作者: xbb123    時間: 2020-12-17 08:51
標題: 基于STC15F單片機的太陽能版追光系統(tǒng)程序與原理圖PCB
Altium Designer畫的原理圖和PCB圖如下:(51hei附件中可下載工程文件)


以下為主函數(shù)內(nèi)容:
  1. #include "GPIO.h"
  2. #include "usart.h"
  3. #include "config.h"
  4. #include "adc.h"
  5. #include "delay.h"

  6. #define Mz P24 //左轉電機端口
  7. #define Mf P25 //右轉電機端口
  8. #define LED1  P20 //左轉LED燈控制端口
  9. #define LED2  P21 //右轉LED燈控制端口
  10. #define P1n_pure_input(bitn)                P1M1 |=  (bitn),        P1M0 &= ~(bitn)


  11. u16 ADC1=0,ADC2=0;


  12. void GPIO_Init_init()                  //GPIO初始化設置
  13. {
  14.          GPIO_InitTypeDef GPIO_Init;
  15.          GPIO_Init.Mode = GPIO_OUT_PP;
  16.          GPIO_Init.Pin = P30|P31;
  17.          GPIO_Inilize(GPIO_P3, &GPIO_Init);

  18.          GPIO_Init.Mode = GPIO_OUT_PP;
  19.          GPIO_Init.Pin = P20|P21;
  20.          GPIO_Inilize(GPIO_P2, &GPIO_Init);
  21. }


  22. void COM1_Init()                                        //串口1初始化設置
  23. {
  24.         COMx_InitDefine COM1_InitDefine;
  25.         COM1_InitDefine.UART_Mode = UART_8bit_BRTx;                        //模式,         UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
  26.         COM1_InitDefine.UART_BRT_Use = BRT_Timer2;                //使用波特率,   BRT_Timer1,BRT_Timer2
  27.         COM1_InitDefine.UART_BaudRate = 115200ul;                //波特率,       ENABLE,DISABLE
  28.         COM1_InitDefine.Morecommunicate = DISABLE;        //多機通訊允許, ENABLE,DISABLE
  29.         COM1_InitDefine.UART_RxEnable = ENABLE;                //允許接收,   ENABLE,DISABLE
  30.         COM1_InitDefine.BaudRateDouble = ENABLE;                //波特率加倍, ENABLE,DISABLE
  31.         COM1_InitDefine.UART_Interrupt = ENABLE;                //中斷控制,   ENABLE,DISABLE
  32.         COM1_InitDefine.UART_Polity = PolityHigh;                //優(yōu)先級,     PolityLow,PolityHigh
  33.         COM1_InitDefine.UART_P_SW = UART1_SW_P30_P31;                        //切換端口,   UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17(必須使用內(nèi)部時鐘)
  34.         COM1_InitDefine.UART_RXD_TXD_Short = DISABLE;        //內(nèi)部短路RXD與TXD, 做中繼, ENABLE,DISABLE
  35.         USART_Configuration(USART1, &COM1_InitDefine);
  36.         //PrintString1("STC15F2K60S2 UART1 Test Prgramme!\r\n");        //SUART1發(fā)送一個字符串
  37. }


  38. void ADC_Init()                                           //ADC10-11初始化
  39. {
  40.         ADC_InitTypeDef ADC_InitType;
  41.         ADC_InitType.ADC_Px = ADC_P10|ADC_P11;                        //設置要做ADC的IO,        ADC_P10 ~ ADC_P17,ADC_P1_All
  42.         ADC_InitType.ADC_Speed = ADC_180T;                //ADC速度                        ADC_90T,ADC_180T,ADC_360T,ADC_540T
  43.         ADC_InitType.ADC_Power = ENABLE;                //ADC功率允許/關閉        ENABLE,DISABLE
  44.         ADC_InitType.ADC_AdjResult = ADC_RES_H8L2;        //ADC結果調整,        ADC_RES_H2L8,ADC_RES_H8L2
  45.         ADC_InitType.ADC_Polity = PolityHigh;                //優(yōu)先級設置        PolityHigh,PolityLow
  46.         ADC_InitType.ADC_Interrupt = DISABLE;        //中斷允許                ENABLE,DISABLE
  47.         ADC_Inilize(&ADC_InitType);
  48.         P1n_pure_input(0x03);
  49. }



  50. void main()
  51. {
  52.         u8 i = 0;
  53.         Mz = Mf = 1;
  54.         GPIO_Init_init(); //GPIO初始化
  55.         COM1_Init(); //串口初始化
  56.         ADC_Init(); //ADC初始化
  57.         ADC_PowerControl(ENABLE); //使能內(nèi)部工作電源ADC
  58.         EA = 1;                //打開總中斷
  59.         while(1)
  60.         {
  61.                 delay_ms(10);
  62.                 ADC1 = Get_ADC10bitResult(ADC_CH0)/10;         //讀ADC0值;除以誤差系數(shù)10
  63.                 ADC2 = Get_ADC10bitResult(ADC_CH1)/10;         //讀ADC1值;除以誤差系數(shù)10
  64. //                TX1_write2buff(ADC1);
  65.                 if(ADC1 == 1024 || ADC2 == 1024)
  66.                 {
  67.                         PrintString1("1024\r\n");
  68.                         continue;
  69.                 }
  70.                 if(ADC1 > ADC2)
  71.                 {        
  72.                         if(i == 2)
  73.                         {
  74.                                 Mz = 1;
  75.                                 Mf = 1;
  76.                                 delay_ms(200);
  77.                                 i = 1;
  78.                         }        
  79.                         Mz = 0;
  80.                         Mf = 1;
  81.                         LED1 = 0;
  82.                         LED2 = 1;
  83.                         PrintString1("左側\r\n");
  84.                 }        
  85.                 else if(ADC1 < ADC2)
  86.                 {  
  87.                         if(i == 1)
  88.                         {
  89.                                 Mz = 1;
  90.                                 Mf = 1;
  91.                                 delay_ms(200);
  92.                                 i = 2;
  93.                         }
  94.                         PrintString1("右側\r\n");
  95.                         Mz = 1;
  96.                         Mf = 0;
  97.                         LED1 = 1;
  98.                         LED2 = 0;
  99.                         
  100.                 }
  101.                 else
  102.                 {  
  103.                         if(i != 0)
  104.                         {
  105.                                 Mz = 1;
  106.                                 Mf = 1;
  107.                                 delay_ms(200);
  108.                                 i = 0;
  109.                         }        
  110.                         Mz = 1;
  111.                         Mf = 1;
  112.                         LED1 = 1;
  113.                         LED2 = 1;
  114.                         PrintString1(".");
  115.                 }
  116.                
  117.         }        
  118. }
復制代碼

全部資料51hei下載地址(程序+PCB+原理圖):
PCB工程文件.7z (3.91 MB, 下載次數(shù): 126)


作者: Chen1108    時間: 2021-6-18 19:03
這個有一百個元器件嗎

作者: htyt520    時間: 2022-3-1 16:48
芯片用的是啥
作者: 296058967    時間: 2022-5-15 13:00
PCB 只畫了單軸輸出




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1