tm1650 驱动

include “tm1650.h”

unsigned char CODE[20] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x73}; //0~9????
__asm void nop(void)
{
NOP
}

void Delay_us(u32 i) //us??
{
for(;i>0;i–)
{
__nop();
// nop();
// nop();
// nop();
// nop();
}
}
void I2CStart(void) //????
{
CLK_H;
DIO_H;
Delay_us(5);
DIO_L;

}

void I2Cask(void) //ACK??
{
u8 timeout = 1;
CLK_H;
Delay_us(5);
CLK_L;
//while((DIO)&&(timeout<=100))
{
timeout++;
}
Delay_us(5);
CLK_L;
}

void I2CStop(void) //????
{
CLK_H;
DIO_L;
Delay_us(5);
DIO_H;
}

void I2CWrByte(u8 oneByte) //?????????,????
{
u8 i;
CLK_L;
Delay_us(1);
for(i=0;i<8;i++)
{

    if(oneByte&0x80)
        DIO_H;
    else
        DIO_L;
    oneByte = oneByte<<1;
    CLK_L;
    Delay_us(5);
    CLK_H;
    Delay_us(5);
    CLK_L;

}

}
void TM1650_Set(u8 add,u8 dat) //?????
{
I2CStart();
I2CWrByte(add);
I2Cask();
I2CWrByte(dat);
I2Cask();
I2CStop();
}
void display(u8 add,u8 dat)
{

switch (add)

{
case 1: TM1650_Set(0x68,CODE[dat]);
break;
case 2: TM1650_Set(0x6A,CODE[dat]);
break;
case 3: TM1650_Set(0x6C,CODE[dat]);
break;
case 4: TM1650_Set(0x6E,CODE[dat]);
break;
default:
break;
}
}
void display_two(u8 dat,u8 dat1)
{
display(1,dat/10);
display(2,dat%10);
display(3,dat1/10);
display(4,dat1%10);
}
void display_Phase(u8 dat,u8 dat1)
{
if(dat1>3) dat1-=3;
display(1,16);
display(2,dat%10);
display(3,dat1/10);
display(4,dat1%10);
}
void display_Set(u8 dat,u8 dat1)
{
display(1,15);
display(2,dat%10);
display(3,dat1/10);
display(4,dat1%10);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// .h文件

ifndef TM1650_H

define TM1650_H

include “stm32f0xx.h”

include “stm32f0xx_tim.h”

define s8 char

define u8 unsigned char

define s16 int

define u16 unsigned int

define s32 long

define u32 unsigned long

define CLK_H GPIO_SetBits(GPIOA,GPIO_Pin_0)

define CLK_L GPIO_ResetBits(GPIOA,GPIO_Pin_0)

define DIO_H GPIO_SetBits(GPIOA,GPIO_Pin_1)

define DIO_L GPIO_ResetBits(GPIOA,GPIO_Pin_1)

void TM1650_Set(unsigned char add,unsigned char dat);
unsigned char Scan_Key(void);
void display(unsigned char add,unsigned char dat);;
void display_two(unsigned char dat,unsigned char dat1);
void display_Phase(u8 dat,u8 dat1);
void display_Set(u8 dat,u8 dat1);

endif

你可能感兴趣的:(tm1650 驱动)