stm32 8位数码管程序c语言,STM32入门例程,595串行8位数码管源程序

/*--------------------------------------

//GPIO define

//Design by :Tan/yicheng

//pctanyicheng@163.com

//www.u-easytech.com

//u-easytech@163.com

//重庆优易特电子

// COPYRIGHT:重庆优易特电子

//http://www.u-easytech.com/chinese/

//FUNCTION:用595完成八位数码管显示

--------------------------------------------------------------------------     */

#include &ltstm32f10x_lib.h&gt              /* STM32F10x Library Definitions      */

#include "UET_GPIO.h"

//unsigned char  seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x8c,0xc1,0xce,0x91,0x89,0xc7,0xff};

unsigned char  seg[]={

0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,

0x77,0x7c,0x39,0x5e,0x79,0x71,0x73,0x78,0x5c,0x54,

0x40,0x81,0x88,0x3e,0x70,0x00

} ;

//0,1,2,3,4,5,6,7,8,9,

//A,b,C,d,E,F,P,t,o,n,

//-,~,_,U,r,SP,

//unsigned char  DAT[]={0x7f,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};           //位选择

unsigned char BitSelect_Code[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};   //因为ULN2803驱动反相,所以位码要用共阳极的位码

//COM1 COM2 COM3 COM4      COM5 COM6 COM7 COM8

// B0   B1  B2     B3    B4   B5   B6   B7

unsigned  char  Disp_buffer[]={0,1,2,3,4,5,6,7};                       //段缓冲区

unsigned  char      Bit_NO=0       ;                        //      选择第Bit_NO位数码管

unsigned  char      Buffer_NO=0;                           //     缓冲区的第Buffer_NO

u32 LED_DATA=01234567;

#define SER(x)             GPIOA-&gtODR=(GPIOA-&gtODR&~GPIO_Pin_7)          | (x ? GPIO_Pin_7 : 0)

#define SCK(x)              GPIOA-&gtODR=(GPIOA-&gtODR&~GPIO_Pin_5)          | (x ? GPIO_Pin_5 : 0)

#define RCK(x)              GPIOA-&gtODR=(GPIOA-&gtODR&~GPIO_Pin_6)          | (x ? GPIO_Pin_6 : 0)

/*******************************************************************************

* Function Name  :  void WR_595(unsigned char segdata)

* Description    : 595串行输入

* Input          : 段码

* Output         : None

* Return         : None

*******************************************************************************/

void WR_595(unsigned char segdata) //输入一字节数码管数据进595

{

unsigned char i,temp;

temp=segdata;

for(i=0;i&lt8;i++)           //循环移入8位数据,

{

SCK(0);

if(temp&0x80)          // 取数码的最高位

SER(1);

else

SER(0);

temp=temp&lt&lt1;

SCK(1);     //上升沿把一位数据移入595

}

}

/*******************************************************************************

* Function Name  : void OUT_595(void)

* Description    : 595锁存输出

* Input          : 段码

* Output         : None

* Return         : None

*******************************************************************************/

void OUT_595(void)      //上升沿将数据送到输出锁存器

{  unsigned i;

RCK(0);

for(i=0;i&lt10;i++)    ;

RCK(1);

RCK(0);

}

/*******************************************************************************

* Function Name  : void LED_Brush(u32 LED_DATA)

* Description    : 数码管缓冲数据刷新

* Input          : u32 LED_DATA

* Output         : None

* Return         : None

*******************************************************************************/

void LED_Brush(u32 LED_DATA)

{

Disp_buffer[0]=LED_DATA/1000%10;

Disp_buffer[1]=LED_DATA/100%10;

Disp_buffer[2]=LED_DATA/10%10;

Disp_buffer[3]=LED_DATA%10;

Disp_buffer[4]=LED_DATA/10000000;

Disp_buffer[5]=LED_DATA/1000000%10;

Disp_buffer[6]=LED_DATA/100000%10;

Disp_buffer[7]=LED_DATA/10000%10;

}

/*******************************************************************************

* Function Name  : void Display(void)

* Description    : 显示

* Input          : None

* Output         : None

* Return         : None

*******************************************************************************/

void Display(void)

{

LED_Brush(12345678);//调用显示函数

WR_595(BitSelect_Code[Bit_NO]);            // 位码

WR_595(seg[Disp_buffer][Buffer_NO]]);    //段码

OUT_595();

Bit_NO++;

Buffer_NO++;

if( Buffer_NO&gt7) Buffer_NO=0;

if(Bit_NO&gt7)Bit_NO=0;

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值