zoukankan      html  css  js  c++  java
  • stm32之595(spi芯片)

      595是一款串转并的芯片;  (三极管的功能)

      1 /*Include---------------------------*/
      2 #include"stm32f10x_lib.h"        //包含所有的头文件
      3 #include<stdio.h>
      4 
      5 //----------------函数声明--------------------
      6 void Delay_MS(u16 dly);
      7 void RCC_Configuration(void);
      8 void GPIO_Configuration(void);
      9 
     10 
     11 /*******************************************************************************
     12 * Function Name  : main
     13 * Description    : Main program.
     14 * Input          : None
     15 * Output         : None
     16 * Return         : None
     17 *******************************************************************************/ 
     18 int main(void)
     19 {
     20     u8  data, i;
     21     #ifdef DEBUG
     22     debug();
     23     #endif
     24     //------------初始化------------
     25     RCC_Configuration();
     26     GPIO_Configuration();
     27 
     28     //------------数码管控制-----------
     29 //smgA1----PC8
     30 //RCK----PA1
     31 //SCK0---SPISCK----PA5
     32 //MISO0-----PA6
     33 //MOSI0-----PA7
     34 //595_nCS----PA0
     35     //PC8 =0;
     36     //SCK0 上升沿; MOSI0:数据输出;
     37     //595_nCS 为0,要送的目标数据是00100101
     38      //RCK上升沿进行锁存;
     39     GPIO_ResetBits(GPIOC, GPIO_Pin_8);
     40     GPIO_ResetBits(GPIOA, GPIO_Pin_0);
     41 
     42     data = 0x25;
     43      for(i=0;i<8;++i)
     44     {
     45         GPIO_ResetBits(GPIOA, GPIO_Pin_5);    //PB5清零
     46         if((data&0x01) == 0x01)              //注意,595是先送 低位 过去;
     47             GPIO_ResetBits(GPIOA, GPIO_Pin_7);
     48         else
     49             GPIO_SetBits(GPIOA, GPIO_Pin_7);
     50         data>>=1;    //右移一位并赋值给data
     51         GPIO_SetBits(GPIOA, GPIO_Pin_5);    //PB5置1,为了产生上升沿    
     52     }
     53 
     54     GPIO_ResetBits(GPIOA, GPIO_Pin_1);  //产生上升沿
     55     Delay_MS(10);
     56     GPIO_SetBits(GPIOA, GPIO_Pin_1);
     57 
     58 
     59 
     60 
     61 //    GPIO_SetBits(GPIOE, GPIO_Pin_11);
     62 //    data = 0x30;
     63 //    for(i=0;i<8;++i)
     64 //    {
     65 //        GPIO_ResetBits(GPIOB, GPIO_Pin_5);    //PB5清零
     66 //        if((data&0x80) == 0x00)
     67 //            GPIO_ResetBits(GPIOE, GPIO_Pin_10);
     68 //        else
     69 //            GPIO_SetBits(GPIOE, GPIO_Pin_10);
     70 //        data<<=1;    //左移一位并赋值给data
     71 //        GPIO_SetBits(GPIOB, GPIO_Pin_5);    //PB5置1,为了产生上升沿    
     72 //    }
     73 //
     74 //
     75 //    while(1)
     76 //    {
     77 //        GPIO_SetBits(GPIOA, GPIO_Pin_3);
     78 //        Delay_MS(1000);
     79 //        GPIO_ResetBits(GPIOA, GPIO_Pin_3);
     80 //        Delay_MS(1000);    
     81 //    }
     82         
     83 }
     84 
     85 /*******************************************************************************
     86 * Function Name  : Delay_Ms
     87 * Description    : delay 1 ms.
     88 * Input          : dly (ms)
     89 * Output         : None
     90 * Return         : None
     91 *******************************************************************************/
     92 void Delay_MS(u16 dly)
     93 {
     94     u16 i,j;
     95     for(i=0;i<dly;i++)
     96         for(j=1000;j>0;j--);
     97 }
     98 
     99 /*******************************************************************************
    100 * Function Name  : RCC_Configuration
    101 * Description    : Configures the different system clocks.
    102 * Input          : None
    103 * Output         : None
    104 * Return         : None
    105 *******************************************************************************/
    106 void RCC_Configuration(void)
    107 {
    108     //----------使用外部RC晶振-----------
    109     RCC_DeInit();            //初始化为缺省值
    110     RCC_HSEConfig(RCC_HSE_ON);    //使能外部的高速时钟 
    111     while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);    //等待外部高速时钟使能就绪
    112     
    113     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);    //Enable Prefetch Buffer
    114     FLASH_SetLatency(FLASH_Latency_2);        //Flash 2 wait state
    115     
    116     RCC_HCLKConfig(RCC_SYSCLK_Div1);        //HCLK = SYSCLK
    117     RCC_PCLK2Config(RCC_HCLK_Div1);            //PCLK2 =  HCLK
    118     RCC_PCLK1Config(RCC_HCLK_Div2);            //PCLK1 = HCLK/2
    119     RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);    //PLLCLK = 8MHZ * 9 =72MHZ
    120     RCC_PLLCmd(ENABLE);            //Enable PLLCLK
    121 
    122     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);    //Wait till PLLCLK is ready
    123     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);    //Select PLL as system clock
    124     while(RCC_GetSYSCLKSource()!=0x08);        //Wait till PLL is used as system clock source
    125     
    126     //---------打开相应外设时钟--------------------
    127     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);    //使能APB2外设的GPIOA的时钟
    128     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);             
    129 }
    130 
    131 /*******************************************************************************
    132 * Function Name  : GPIO_Configuration
    133 * Description    : 初始化GPIO外设
    134 * Input          : None
    135 * Output         : None
    136 * Return         : None
    137 *******************************************************************************/
    138 void GPIO_Configuration(void)
    139 {
    140     //CLK:PB5  CLR:PE11 DATA:PE10
    141     
    142 //smgA1----PC8
    143 //RCK----PA1
    144 //SCK0---SPISCK----PA5
    145 //MISO0-----PA6
    146 //MOSI0-----PA7
    147 //595_nCS----PA0
    148 
    149     GPIO_InitTypeDef    GPIO_InitStructure;        //声明一个结构体变量
    150     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_5|GPIO_Pin_7;     //选择PB.5
    151     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;     //管脚频率为50MHZ
    152     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     //输出模式为推挽输出
    153     GPIO_Init(GPIOA,&GPIO_InitStructure);                 //初始化GPIOB寄存器
    154     
    155     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;     //选择PE.10 PE.11
    156     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;     //管脚频率为50MHZ
    157     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   //输出模式为推挽输出
    158     GPIO_Init(GPIOA,&GPIO_InitStructure);                 //初始化GPIOE寄存器
    159    
    160        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;     //选择PB.5
    161     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;     //管脚频率为50MHZ
    162     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     //输出模式为推挽输出
    163     GPIO_Init(GPIOC,&GPIO_InitStructure);                 //初始化GPIOB寄存器
    164         
    165     //开启时钟    必须在RCC_Configuration中设置        
    166 }
  • 相关阅读:
    分布式任务框架elastic-job 学习笔记
    spring 基础知识复习
    Spring MVC 搭建
    python引入自定义模块
    python操作Excel读写--使用xlrd
    selenium2.0关于python的常用函数
    从零开始学Python07作业源码:虚拟人生(仅供参考)
    通过System.getProperties()获取系统参数
    Android Studio启动后出现cannot bind to 127.0.0.1:5037 10048的解决办法
    开发环境入门 linux基础 (部分)awk 赋值变量 if
  • 原文地址:https://www.cnblogs.com/chris-cp/p/3918327.html
Copyright © 2011-2022 走看看