久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5537|回復: 7
打印 上一主題 下一主題
收起左側

stm32交通燈程序設計

  [復制鏈接]
跳轉到指定樓層
樓主
ID:464849 發表于 2019-1-8 20:04 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #include "stm32f10x.h"
  2. #include "delay.h"

  3. void Delay(u16 nCount);
  4. void GPIO_Config(void)
  5. {
  6.          GPIO_InitTypeDef        GPIO_InitStructure;
  7.         
  8.   GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
  9.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  10.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  11.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  12.         

  13.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
  14.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  15.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  16.   GPIO_Init(GPIOA,&GPIO_InitStructure);
  17.         
  18.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
  19.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  20.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
  21.   GPIO_Init(GPIOA,&GPIO_InitStructure);
  22. }
  23.   
  24.         void SPI_Config(void)
  25.         {
  26.         SPI_InitTypeDef  SPI1_InitStructure;
  27.         SPI1_InitStructure.SPI_Direction=SPI_Direction_2Lines_FullDuplex;//設置SPI單向或者雙向的數據模式:SPI設置為雙線模式
  28.         SPI1_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_64;//定義波特率預分頻的值:波特率預分頻值為64
  29.         SPI1_InitStructure.SPI_DataSize=SPI_DataSize_8b;//設置SPI的數據大小:SPI發送接收8位幀結構
  30.         SPI1_InitStructure.SPI_Mode=SPI_Mode_Master;//設置SPI工作模式,設置為主模式
  31.         SPI1_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB; //高位在先
  32.         SPI1_InitStructure.SPI_CPOL = SPI_CPOL_High;//串行同步時鐘的空閑狀態為高電平                                       
  33.         SPI1_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //串行同步時鐘的第二個跳變沿(上升或下降)數據被采樣
  34.         SPI1_InitStructure.SPI_NSS = SPI_NSS_Soft; // 使用軟件模式
  35.         SPI1_InitStructure.SPI_CRCPolynomial = 7; //CRC值計算的多項式
  36.         SPI_I2S_DeInit(SPI1);
  37.         SPI_Init(SPI1, &SPI1_InitStructure); //初始化
  38.   SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set);//內部制高電平
  39.         SPI_Cmd(SPI1, ENABLE);  
  40.         }
  41.         
  42.         void Write_Max7219(u8 address,u8 dat)
  43. {
  44.   //功能:向MAX7219寫入數據
  45.   //入口參數:address、dat
  46.   //出口參數:無
  47.   //說明:
  48.                         GPIO_ResetBits(GPIOA, GPIO_Pin_3);        
  49.       SPI_I2S_SendData(SPI1, address);  //寫入地址,即數碼管編號
  50.             delay_us(10);
  51.             SPI_I2S_SendData(SPI1, dat);            //寫入數據,即數碼管顯示數字
  52.             delay_us(10);
  53.                         GPIO_SetBits(GPIOA, GPIO_Pin_3);
  54. }

  55. void Init_MAX7219(void)
  56. {
  57. Write_Max7219(0x09, 0xff);       //譯碼方式:BCD碼
  58. Write_Max7219(0x0a, 0x05);       //亮度
  59. Write_Max7219(0x0b, 0x07);       //掃描界限8個數碼管顯示
  60. Write_Max7219(0x0c, 0x01);       //掉電模式:0,普通模式:1
  61. Write_Max7219(0x0f, 0x00);       //顯示測試:1;測試結束,正常顯示:0
  62. }

  63. int main(void)
  64. {
  65.         
  66.         
  67.         
  68.         
  69.         
  70.           RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE);
  71.           RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  72.           delay_init();
  73.                 GPIO_Config();
  74.                 SPI_Config();
  75.           Init_MAX7219();
  76.         
  77.         GPIO_SetBits(GPIOA, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
  78.         
  79.         

  80.         
  81.                 while(1)
  82.         {
  83. GPIO_SetBits(GPIOA, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10);
  84.                 GPIO_ResetBits(GPIOA,GPIO_Pin_10|GPIO_Pin_1);
  85.                  
  86.                
  87.                 Write_Max7219(0x01, 0x04);
  88.            Write_Max7219(0x02, 0x01);
  89.                 Write_Max7219(0x03, 0x0f);
  90.            Write_Max7219(0x04, 0x0f);
  91.      Write_Max7219(0x05, 0x0f);
  92.            Write_Max7219(0x06, 0x0f);
  93.                 Write_Max7219(0x07, 0x01);
  94.            Write_Max7219(0x08, 0x01);
  95.             delay_ms(1000);
  96.                  Write_Max7219(0x01, 0x03);
  97.            Write_Max7219(0x02, 0x01);
  98.                  Write_Max7219(0x07, 0x00);
  99.            Write_Max7219(0x08, 0x01);
  100.                 Write_Max7219(0x03, 0x0f);
  101.            Write_Max7219(0x04, 0x0f);
  102.      Write_Max7219(0x05, 0x0f);
  103.            Write_Max7219(0x06, 0x0f);
  104.           delay_ms(1000);
  105.                  Write_Max7219(0x01, 0x02);
  106.            Write_Max7219(0x02, 0x01);
  107.                 Write_Max7219(0x03, 0x09);
  108.            Write_Max7219(0x04, 0x00);
  109.                  Write_Max7219(0x03, 0x0f);
  110.            Write_Max7219(0x04, 0x0f);
  111.      Write_Max7219(0x05, 0x0f);
  112.            Write_Max7219(0x06, 0x0f);
  113.                  delay_ms(1000);
  114.                  Write_Max7219(0x01, 0x01);
  115.            Write_Max7219(0x02, 0x01);
  116.                  Write_Max7219(0x07, 0x08);
  117.            Write_Max7219(0x08, 0x00);
  118.                  Write_Max7219(0x03, 0x0f);
  119.            Write_Max7219(0x04, 0x0f);
  120.      Write_Max7219(0x05, 0x0f);
  121.            Write_Max7219(0x06, 0x0f);
  122.                   delay_ms(1000);
  123.                  Write_Max7219(0x01, 0x00);
  124.            Write_Max7219(0x02, 0x01);
  125.           Write_Max7219(0x07, 0x07);
  126.            Write_Max7219(0x08, 0x00);
  127.                  Write_Max7219(0x03, 0x0f);
  128.            Write_Max7219(0x04, 0x0f);
  129.      Write_Max7219(0x05, 0x0f);
  130.            Write_Max7219(0x06, 0x0f);
  131.                  delay_ms(1000);
  132.                  Write_Max7219(0x01, 0x09);
  133.            Write_Max7219(0x02, 0x00);
  134.                 Write_Max7219(0x07, 0x06);
  135.            Write_Max7219(0x08, 0x00);
  136.                  Write_Max7219(0x03, 0x0f);
  137.            Write_Max7219(0x04, 0x0f);
  138.      Write_Max7219(0x05, 0x0f);
  139.            Write_Max7219(0x06, 0x0f);
  140.                  delay_ms(1000);
  141.                  Write_Max7219(0x01, 0x08);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  142.            Write_Max7219(0x02, 0x00);
  143.                 Write_Max7219(0x07, 0x05);
  144.            Write_Max7219(0x08, 0x00);
  145.                  Write_Max7219(0x03, 0x0f);
  146.            Write_Max7219(0x04, 0x0f);
  147.      Write_Max7219(0x05, 0x0f);
  148.            Write_Max7219(0x06, 0x0f);
  149.                  delay_ms(1000);
  150.                  Write_Max7219(0x01, 0x07);
  151.            Write_Max7219(0x02, 0x00);
  152.                 Write_Max7219(0x07, 0x04);
  153.            Write_Max7219(0x08, 0x00);
  154.                  Write_Max7219(0x03, 0x0f);
  155.            Write_Max7219(0x04, 0x0f);
  156.      Write_Max7219(0x05, 0x0f);
  157.            Write_Max7219(0x06, 0x0f);
  158.                  delay_ms(1000);
  159.                  Write_Max7219(0x01, 0x06);
  160.            Write_Max7219(0x02, 0x00);
  161.                  Write_Max7219(0x07, 0x03);
  162.            Write_Max7219(0x08, 0x00);
  163.                  Write_Max7219(0x03, 0x0f);
  164.            Write_Max7219(0x04, 0x0f);
  165.      Write_Max7219(0x05, 0x0f);
  166.            Write_Max7219(0x06, 0x0f);
  167.                  delay_ms(1000);
  168.                  Write_Max7219(0x01, 0x05);
  169.            Write_Max7219(0x02, 0x00);
  170.                  Write_Max7219(0x07, 0x02);
  171.            Write_Max7219(0x08, 0x00);
  172.                  Write_Max7219(0x03, 0x0f);
  173.            Write_Max7219(0x04, 0x0f);
  174.      Write_Max7219(0x05, 0x0f);
  175.            Write_Max7219(0x06, 0x0f);
  176.                  delay_ms(1000);
  177.                  Write_Max7219(0x01, 0x04);
  178.            Write_Max7219(0x02, 0x00);
  179.                  Write_Max7219(0x07, 0x01);
  180.            Write_Max7219(0x08, 0x00);
  181.                  Write_Max7219(0x03, 0x0f);
  182.            Write_Max7219(0x04, 0x0f);
  183.      Write_Max7219(0x05, 0x0f);
  184.            Write_Max7219(0x06, 0x0f);
  185.                  delay_ms(1000);
  186. GPIO_SetBits(GPIOA, GPIO_Pin_10);
  187.          
  188.                  
  189.                  
  190.                  GPIO_ResetBits(GPIOA, GPIO_Pin_9);
  191.                  Write_Max7219(0x01, 0x03);
  192.            Write_Max7219(0x02, 0x00);
  193.                  Write_Max7219(0x07, 0x03);
  194.            Write_Max7219(0x08, 0x00);
  195.                  Write_Max7219(0x03, 0x0f);
  196.            Write_Max7219(0x04, 0x0f);
  197.      Write_Max7219(0x05, 0x0f);
  198.            Write_Max7219(0x06, 0x0f);
  199.                  delay_ms(1000);
  200.                  Write_Max7219(0x01, 0x02);
  201.            Write_Max7219(0x02, 0x00);
  202.                  Write_Max7219(0x07, 0x02);
  203.            Write_Max7219(0x08, 0x00);
  204.                  Write_Max7219(0x03, 0x0f);
  205.            Write_Max7219(0x04, 0x0f);
  206.      Write_Max7219(0x05, 0x0f);
  207.            Write_Max7219(0x06, 0x0f);
  208.            delay_ms(1000);
  209.                  Write_Max7219(0x01, 0x01);
  210.            Write_Max7219(0x02, 0x00);
  211.                  Write_Max7219(0x07, 0x01);
  212.            Write_Max7219(0x08, 0x00);
  213.                  Write_Max7219(0x03, 0x0f);
  214.            Write_Max7219(0x04, 0x0f);
  215.      Write_Max7219(0x05, 0x0f);
  216.            Write_Max7219(0x06, 0x0f);
  217.            delay_ms(1000);
  218.           GPIO_SetBits(GPIOA, GPIO_Pin_9|GPIO_Pin_1);
  219.                
  220.                  GPIO_ResetBits(GPIOA, GPIO_Pin_8|GPIO_Pin_2);
  221.                 Write_Max7219(0x01, 0x02);
  222.            Write_Max7219(0x02, 0x01);
  223.            Write_Max7219(0x07, 0x05);
  224.            Write_Max7219(0x08, 0x01);
  225.                  Write_Max7219(0x03, 0x0f);
  226.            Write_Max7219(0x04, 0x0f);
  227.      Write_Max7219(0x05, 0x0f);
  228.            Write_Max7219(0x06, 0x0f);
  229.            delay_ms(1000);
  230.                 Write_Max7219(0x01, 0x01);
  231.            Write_Max7219(0x02, 0x01);
  232.            Write_Max7219(0x07, 0x04);
  233.            Write_Max7219(0x08, 0x01);
  234.                  Write_Max7219(0x03, 0x0f);
  235.            Write_Max7219(0x04, 0x0f);
  236.      Write_Max7219(0x05, 0x0f);
  237.            Write_Max7219(0x06, 0x0f);
  238.             delay_ms(1000);
  239.                  Write_Max7219(0x01, 0x00);
  240.            Write_Max7219(0x02, 0x01);
  241.                  Write_Max7219(0x07, 0x03);
  242.            Write_Max7219(0x08, 0x01);
  243.                  Write_Max7219(0x03, 0x0f);
  244.            Write_Max7219(0x04, 0x0f);
  245.      Write_Max7219(0x05, 0x0f);
  246.            Write_Max7219(0x06, 0x0f);
  247.           delay_ms(1000);
  248.                  Write_Max7219(0x01, 0x09);
  249.            Write_Max7219(0x02, 0x00);
  250.                 Write_Max7219(0x07, 0x02);
  251.            Write_Max7219(0x08, 0x01);
  252.                  Write_Max7219(0x03, 0x0f);
  253.            Write_Max7219(0x04, 0x0f);
  254.      Write_Max7219(0x05, 0x0f);
  255.            Write_Max7219(0x06, 0x0f);
  256.                  delay_ms(1000);
  257.                  Write_Max7219(0x01, 0x08);
  258.            Write_Max7219(0x02, 0x00);
  259.                  Write_Max7219(0x07, 0x01);
  260.            Write_Max7219(0x08, 0x01);
  261.                  Write_Max7219(0x03, 0x0f);
  262.            Write_Max7219(0x04, 0x0f);
  263.      Write_Max7219(0x05, 0x0f);
  264.            Write_Max7219(0x06, 0x0f);
  265.                   delay_ms(1000);
  266.                  Write_Max7219(0x01, 0x07);
  267.            Write_Max7219(0x02, 0x00);
  268.                 Write_Max7219(0x03, 0x00);
  269.            Write_Max7219(0x04, 0x01);
  270.                  Write_Max7219(0x03, 0x0f);
  271.            Write_Max7219(0x04, 0x0f);
  272.      Write_Max7219(0x05, 0x0f);
  273.            Write_Max7219(0x06, 0x0f);
  274.                  delay_ms(1000);
  275.                  Write_Max7219(0x01, 0x06);
  276.            Write_Max7219(0x02, 0x00);
  277.                 Write_Max7219(0x07, 0x09);
  278.            Write_Max7219(0x08, 0x00);
  279.                  Write_Max7219(0x03, 0x0f);
  280.            Write_Max7219(0x04, 0x0f);
  281.      Write_Max7219(0x05, 0x0f);
  282.            Write_Max7219(0x06, 0x0f);
  283.                  delay_ms(1000);
  284.                  Write_Max7219(0x01, 0x05);
  285.            Write_Max7219(0x02, 0x00);
  286.                 Write_Max7219(0x07, 0x08);
  287.            Write_Max7219(0x08, 0x00);
  288.                  Write_Max7219(0x03, 0x0f);
  289.            Write_Max7219(0x04, 0x0f);
  290.      Write_Max7219(0x05, 0x0f);
  291.            Write_Max7219(0x06, 0x0f);
  292.                  delay_ms(1000);
  293.                  Write_Max7219(0x01, 0x04);
  294.            Write_Max7219(0x02, 0x00);
  295.                 Write_Max7219(0x03, 0x07);
  296.            Write_Max7219(0x04, 0x00);
  297.                  Write_Max7219(0x03, 0x0f);
  298.            Write_Max7219(0x04, 0x0f);
  299.      Write_Max7219(0x05, 0x0f);
  300.            Write_Max7219(0x06, 0x0f);
  301.                  delay_ms(1000);
  302.                  Write_Max7219(0x01, 0x03);
  303.            Write_Max7219(0x02, 0x00);
  304.                 Write_Max7219(0x07, 0x06);
  305.            Write_Max7219(0x08, 0x00);
  306.                  Write_Max7219(0x03, 0x0f);
  307.            Write_Max7219(0x04, 0x0f);
  308.      Write_Max7219(0x05, 0x0f);
  309.            Write_Max7219(0x06, 0x0f);
  310.                  delay_ms(1000);
  311.                  Write_Max7219(0x01, 0x02);
  312.            Write_Max7219(0x02, 0x00);
  313.                 Write_Max7219(0x07, 0x05);
  314.            Write_Max7219(0x08, 0x00);
  315.                  Write_Max7219(0x03, 0x0f);
  316.            Write_Max7219(0x04, 0x0f);
  317.      Write_Max7219(0x05, 0x0f);
  318.            Write_Max7219(0x06, 0x0f);
  319.                  delay_ms(1000);
  320.                  Write_Max7219(0x01, 0x01);
  321.            Write_Max7219(0x02, 0x00);
  322.                  Write_Max7219(0x07, 0x04);
  323.            Write_Max7219(0x08, 0x00);
  324.                  Write_Max7219(0x03, 0x0f);
  325.            Write_Max7219(0x04, 0x0f);
  326.      Write_Max7219(0x05, 0x0f);
  327.            Write_Max7219(0x06, 0x0f);
  328.                  delay_ms(1000);
  329.                  
  330.           GPIO_SetBits(GPIOA, GPIO_Pin_2);
  331.                  
  332.                 GPIO_ResetBits(GPIOA, GPIO_Pin_0);
  333.                 Write_Max7219(0x01, 0x03);
  334.            Write_Max7219(0x02, 0x00);
  335.                  Write_Max7219(0x07, 0x03);
  336.            Write_Max7219(0x08, 0x00);
  337.                  Write_Max7219(0x03, 0x0f);
  338.            Write_Max7219(0x04, 0x0f);
  339.      Write_Max7219(0x05, 0x0f);
  340.            Write_Max7219(0x06, 0x0f);
  341.                  delay_ms(1000);
  342.                  Write_Max7219(0x01, 0x02);
  343.            Write_Max7219(0x02, 0x00);
  344.                  Write_Max7219(0x07, 0x02);
  345.            Write_Max7219(0x08, 0x00);
  346.                  Write_Max7219(0x03, 0x0f);
  347.            Write_Max7219(0x04, 0x0f);
  348.      Write_Max7219(0x05, 0x0f);
  349.            Write_Max7219(0x06, 0x0f);
  350.            delay_ms(1000);
  351.                  Write_Max7219(0x01, 0x01);
  352.            Write_Max7219(0x02, 0x00);
  353.                  Write_Max7219(0x07, 0x01);
  354.            Write_Max7219(0x08, 0x00);
  355.                  Write_Max7219(0x03, 0x0f);
  356.            Write_Max7219(0x04, 0x0f);
  357.      Write_Max7219(0x05, 0x0f);
  358.            Write_Max7219(0x06, 0x0f);
  359.            delay_ms(1000);
  360.                  
  361.            GPIO_SetBits(GPIOA, GPIO_Pin_4|GPIO_Pin_0);

  362.         }
  363. }
  364. void Delay(u16 nCount)
  365. {
  366.   for(; nCount != 0; nCount--);
  367. }
復制代碼

交通燈 max.7z

203.96 KB, 下載次數: 90, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:1 發表于 2019-1-8 21:32 | 只看該作者
補全原理圖或者詳細說明一下電路連接即可獲得100+黑幣
回復

使用道具 舉報

板凳
ID:464849 發表于 2019-1-9 10:19 | 只看該作者
原理圖在此

32.png (45.51 KB, 下載次數: 168)

32.png

LED燈.png (18.04 KB, 下載次數: 157)

LED燈.png

晶振.png (15.32 KB, 下載次數: 223)

晶振.png

數碼管電路.png (38.22 KB, 下載次數: 161)

數碼管電路.png

總體原理圖.png (61.86 KB, 下載次數: 161)

總體原理圖.png

最小系統.png (14.31 KB, 下載次數: 148)

最小系統.png

評分

參與人數 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎勵!

查看全部評分

回復

使用道具 舉報

地板
ID:564646 發表于 2019-6-23 16:04 | 只看該作者
樓主,PCB的圖有嗎,新手小白想聯系一下布線
回復

使用道具 舉報

5#
ID:386703 發表于 2019-6-25 14:24 | 只看該作者
樓主,請問有Proteus的仿真圖嗎
回復

使用道具 舉報

6#
ID:666560 發表于 2019-12-17 18:32 | 只看該作者
請問樓主有delay.h文件嗎?方便發一下嗎?
回復

使用道具 舉報

7#
ID:880524 發表于 2021-6-4 19:55 | 只看該作者
大佬有沒有仿真源文件
回復

使用道具 舉報

8#
ID:1007094 發表于 2022-4-11 17:37 | 只看該作者

有沒有圖紙文件
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 青草久久免费视频 | 亚洲最新网址 | 亚洲高清视频在线观看 | 成人激情视频在线观看 | 夜夜草av| 天天看天天操 | 国产乱码精品1区2区3区 | 精品国产91| 欧美一级二级视频 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 欧美综合自拍 | 亚洲aⅴ| 日韩成人| 天天射天天干 | 国产精品国产三级国产aⅴ原创 | 久久成人精品视频 | 国产亚洲第一页 | 91九色在线观看 | 亚洲成人日韩 | 日产久久 | 999免费网站 | 激情综合五月 | 国产精品1区2区 | 亚洲一区二区免费电影 | 欧美精品1区 | 欧美日韩国产一区 | 一区二区福利视频 | 亚洲国产精品视频一区 | a视频在线观看 | 精品久久久久久亚洲精品 | 在线亚洲电影 | 国产精品一区二区欧美黑人喷潮水 | 91精品国产自产在线老师啪 | 一级免费毛片 | 欧美成人激情视频 | 日本天堂视频 | 欧美在线一区二区三区 | 成人一区二区在线 | 久久久www成人免费精品 | 亚洲精品一区二三区不卡 | 精品国产伦一区二区三区观看说明 |