嵌入式开发模拟的电池充放电

嵌入式开发模拟的电池充放电嵌入式开发模拟的电池充电#include”stm32f10x.h”#defineuintunsignedintuint16_tarr[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92

嵌入式开发模拟的电池充放电

#include "stm32f10x.h"
#define uint unsigned int
uint16_t arr[]={ 
   0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint16_t disp[2];
uint temp,a,b,c,t;
void delay()
{ 
   
    uint i,j;
    for(i=0;i<75;i++)
    for(j=0;j<75;j++);
}
int main(void)
{ 
   
	GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);
    GPIO_InitStructure.GPIO_Pin=0xffff;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
    GPIO_Write(GPIOA,0xffff);   
    GPIO_Init(GPIOB,&GPIO_InitStructure);
    GPIO_Init(GPIOC,&GPIO_InitStructure);
    GPIO_Write(GPIOC,0xffff);  
    while(1)
    { 
   
        GPIO_Write(GPIOB,0xfffd);  //红灯
        for(a=0;a<100;a++)     //充电
        { 
   
            disp[1]=arr[a/10];       
            disp[0]=arr[a%10];
            temp=(disp[1]<<8)|(disp[0]&0x00ff);
            GPIO_Write(GPIOC,temp);      //数码管显示
            delay();
            if(disp[1]==0xf9)         //电池容量分层
                t=0x7fff;
            else if(disp[1]==0xa4)
                t=0x7fff>>1;
            else if(disp[1]==0xb0)
                t=0x7fff>>2;
            else if(disp[1]==0x99)
                t=0x7fff>>3;
            else if(disp[1]==0x92)
                t=0x7fff>>4;
            else if(disp[1]==0x82)
                t=0x7fff>>5;
            else if(disp[1]==0xf8)
                t=0x7fff>>6;
            else if(disp[1]==0x80)
                t=0x7fff>>7;
            else if(disp[1]==0x90)
                t=0x7fff>>8;
            else
                t=0x7fff;
            for(b=0;b<10;b++)
            { 
             
                GPIO_Write(GPIOA,t);  //电池容量灯
                t=t>>1;
                delay();
            }           
        }                                   
        GPIO_Write(GPIOA,0x0000);   /
        GPIO_Write(GPIOB,0Xfffe);   //绿灯
        for(c=0;c<100;c++)      //数码管闪烁
        { 
   
            GPIO_Write(GPIOC,temp);
            delay();
            GPIO_Write(GPIOC,0xffff);
        }
        GPIO_Write(GPIOB,0xfffb);   //切换为黄灯放电
        for(a=99;a>0;a--)          //数码管
        { 
   
            disp[1]=arr[a/10];
            disp[0]=arr[a%10];
            temp=(disp[1]<<8)|(disp[0]&0x00ff);
            GPIO_Write(GPIOC,temp);
            delay();
            if(disp[1]==0xf9)     //电池容量分层
                t=0x7fff;
            else if(disp[1]==0xa4)
                t=0x3fff;
            else if(disp[1]==0xb0)
                t=0x1fff;
            else if(disp[1]==0x99)
                t=0x0fff;
            else if(disp[1]==0x92)
                t=0x07ff;
            else if(disp[1]==0x82)
                t=0x03ff;
            else if(disp[1]==0xf8)
                t=0x01ff;
            else if(disp[1]==0x80)
                t=0x00ff;
            else if(disp[1]==0x90)
                t=0x007f;
            else
                t=0x7fff;                  
            GPIO_Write(GPIOA,t);     //电池容量显示
            for(b=0;b<25;b++)	//放电数码管显示延迟
                delay();                        
        } 
    }
}

电路图

嵌入式开发下模拟电池充放电

今天的文章嵌入式开发模拟的电池充放电分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/62357.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注