/*-------------------------------------- //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 <stm32f10x_lib.h> /* 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->ODR=(GPIOA->ODR&~GPIO_Pin_7) | (x ? GPIO_Pin_7 : 0) #define SCK(x) GPIOA->ODR=(GPIOA->ODR&~GPIO_Pin_5) | (x ? GPIO_Pin_5 : 0) #define RCK(x) GPIOA->ODR=(GPIOA->ODR&~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<8;i++) //循环移入8位数据, { SCK(0); if(temp&0x80) // 取数码的最高位 SER(1); else SER(0); temp=temp<<1; 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<10;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>7) Buffer_NO=0; if(Bit_NO>7)Bit_NO=0;
} |