资源描述
数控直流稳压电源Design of numerical control D.C stabilized source based on SCM目录设计任务与要求1摘要2一、方案论证与比较31.1控制器部分31.2 按键控制模块31.3显示部分3二、系统的具体设计及实现42.1系统总框图42.2硬件设计42.3 128*64液晶屏显示设计5数控直流稳压电源论文设计任务与要求一、 设计任务设计并制作一个直流可调稳压电源。二、 设计要求1、基本要求:1) 当输入交流电压为220v10%时,输出电压在0-13v可调;2) 额定电流为1A,且纹波不大于1mV;3) 使用按键设定电压,同时具有常用电平快速切换功能(3v、5v、6v、9v、12v),设定后按键可锁定,防止误触;4) 掉电后可记忆上次的设定值;5) 显示设定电压和测量电压、电流,显示精度为0.01v。6) 两级过流保护功能,当电流超过额定值的20%达5秒时,电路作断开操作;当电流超过额定值的50%时,电路立即断开。具有声音和光提示;。摘要在现代家庭中各种电器的不断出现,并要求着各种不同值的电源出现,使得家庭购买不同值得电源。数字化的也更加贴近人们的生活,因为它更加的直观,易被接受,大家都开始追求数字化的各类电子产品。数控直流电源有着直观,易操作,各种电压集一身, 输出精度和稳定性都较高等优点,所以越来越受广大人们的喜爱。以后家里的电视遥控,电动玩具等都可以共用一个电源。本系统以 Amega16 avr单片机作为系统的核心,由D/A数字模拟转换模块、按键、12864液晶显示模块、at24c02等模块组成一个数控电源。该系统实现了 输出电压:范围 0 13 .0 V,纹波不大于10mV;输出电流:1A;输出电压值由12864液晶显示;由“”、“”四个按键控制输出电压不同大小的步进增减 。同时具有常用电平快速切换功能(3v、5v、6v、9v、12v),设定后按键可锁定,防止误触;掉电后可记忆上次的设定值。 关键词: mega16 单片机, 数控电源, D/A, A/D直流电源、LCD12864、at24c02、锁定、电压放大Summary:In the modern family of the various appliances, and asked for a different value power, the family is the power to buy different. the digital has become even more to the peoples life, for it is more intuitive and easy to be accepted, everybody began to pursue the digital of electronic products. numerical dc power supply is intuitive and easy operation, the voltage is set, the output of precision and stability are higher, so it is becoming more and more extensive of the house.From now on, the TV remote control, electric toy all can share a power.The system for amega16 avr monolithic integrated circuit is the core of a system, the d a digital simulation exercise, buttons, 12864 lcd display, such as a numerical at24c02 composed of modules. the system power to output voltages : range of 013. 0 0 v, of waves, not greater than 10mv ; output current : 1a ; output value by 12864 lcd display ; by and four key control output voltage with the size of the step into the decrease. It can used a level rapidly function ( 3v, 5v, 6v, 9v, 12v ), and presses are lockable to prevent touch their combs. Also it memories set value last time. Keyword:Mega16, monolithic integrated circuits, and d a, a dc power and spells lcd12864, at24c02, lock, voltage enlarged一、方案论证与比较1.1控制器部分方案一:采用AT89S52单片机作为主控芯片。优点:AT89S52作为一种比较成熟的单片机型号,广范应用于各领域技术比较熟练,价格相对便宜。缺点:其驱动能力不强方案二:采用Amega16单片机作为主控芯片。优点:AVR是51的升级版。Amega16单片机功能强、高速度是其主要的优点,内部集成了较多的中断源和定时器资源及EEPROM的优点,多种模式的PWM波形输出,很好地满足了本系统设计的要求。缺点:价格较AT89S52单片机高。考虑到以上两种方案的优缺点,因本系统对单片机内部硬件资源的要求比较高,需要采用高速和功能强大的单片机型号。经比较,我们采用了方案二。1.2 按键控制模块方案一:采用矩阵键盘,由于按键多可实现电压值的直接键入。方案二:采用一般的电平判键按钮,实现方法很简单,但一个端口最多只实现8个按键。由于本数控电源设置需要用的按键功能多,故采用方案一。1.3显示部分方案一 使用LCD1602液晶显示。优点:介格便宜;操作简单,带中文字库,使用方便。缺点:显示的内容少(16格*2行),方案二 应用128*64液晶显示模块。128*64液晶可视面积大,介面美观,抗干扰能力强,调用方便简单,而且可以节省软件中断资源,应用串行连接,节省I/O口资源。对图形和曲线的显示实现起来比较简单,自带中文字库,显示信息量大。方案三 使用led灯显示 优点:操作简单 缺点:信息显示不直观通过比较,并结合本系统要显示是内容较多的要求,我们选节方案二。二、系统的具体设计及实现2.1系统总框图主控芯片板电压输出Amega16 单片机LM324电压放大 Led、蜂鸣器工作状态提醒At24c02数据存储12864液晶模块键盘模块AD558电流采样220整流滤波经7805转换供电图2-1、系统主控芯片板总框图2.2硬件设计2.3 128*64液晶屏显示设计本系统采用128*64中文液晶模块作为显示部分,能够显示汉字和字符,只要把需要显示的内容发给液晶模块,其便会自动显示,不时要定时扫描。为了节省IO口资源,液晶模块和单片机的连联采用串行接口,只占用三个IO口,连接图如下图2-3.1所示。 图2-3.1 128*64液晶连接图3.8整板电路硬件设计原理图完整的系统源代码#include #include #define uchar unsigned char#define uint unsigned intuint mega16_ad0() uint addata; DDRA&=BIT(PA0); PORTA&=BIT(PA0); ADMUX=0; ADCSR=0X80; ADCSR|=BIT(ADSC); while(!(ADCSR&(BIT(ADIF); addata=ADCL; addata=addata+ADCH*256; return addata;#include#include#define uchar unsigned char#define uint unsigned int#define DATE_DDR DDRB#define DATE_PORT PORTB#define DATE_PIN PINB#define CS_H DATE_PORT|=BIT(2)#define CS_L DATE_PORT&=BIT(2)#defineSCLK_HDATE_PORT|=BIT(4)#defineSCLK_L DATE_PORT&=BIT(4)#defineSTD_HDATE_PORT|=BIT(3)#defineSTD_L DATE_PORT&=BIT(3)/cs(rs) sclk(e) std(r/w)#defineSTD_OUT DATE_DDR|=BIT(3)#defineSTD_IN DATE_DDR&=BIT(3)#defineSTD_IN_DATE (DATE_PIN&0x08)3/DATE_PIN&0x08PB3std/#define rst_set DATE_PORT|=BIT(4)/#define rst_clear DATE_PORT&=BIT(4)#define psb_set DATE_PORT&=BIT(5)#define DATE_DDR_out DATE_DDR|=0XE0extern delay(uint); /* * */unsigned char _flash AC_TABLE=0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, ; /* */_flash unsigned char bmp8=/*- C:UsersCanwei LuoDesktop-1.bmp -*/*- x=128x64 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x4F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x4F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF9,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x47,0xFF,0xF8,0x1F,0xFF,0xE0,0x3F,0xFF,0xC1,0xFF,0xFE,0x0F,0xFF,0xF1,0x00,0x00,0x44,0x00,0x08,0x10,0x00,0x20,0x20,0x00,0x41,0x00,0x02,0x08,0x00,0x11,0x00,0x00,0x44,0x00,0x08,0x10,0x00,0x20,0x20,0x00,0x41,0x00,0x02,0x08,0x00,0x11,0x00,0x00,0x44,0x00,0x08,0x10,0x00,0x20,0x20,0x00,0x41,0x00,0x02,0x08,0x00,0x11,0x00,0x00,0x44,0x00,0x08,0x10,0x00,0x20,0x20,0x00,0x41,0x00,0x02,0x08,0x00,0x11,0x00,0x00,0x44,0x00,0x08,0x10,0x00,0x20,0x20,0x00,0x41,0x00,0x02,0x08,0x00,0x11,0x00,0x00,0x47,0xFF,0xF8,0x1F,0xFF,0xE0,0x3F,0xFF,0xC1,0xFF,0xFE,0x0F,0xFF,0xF1,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00;void delayms(unsigned int t)unsigned int i;unsigned char j;for(i=0;it;i+)for(j=0;j300;j+)NOP();/*:SendByte():unsigned char Dbyte:12864 :Dbyte12864 */void SendByte(unsigned char Dbyte)unsigned char i;STD_OUT; /for(i=0;i8;i+)SCLK_L;NOP();NOP(); if(Dbyte&0x80) STD_H;/1 else STD_L;/0 SCLK_H;NOP();NOP();SCLK_L;Dbyte=Dbyte1;/8/* : ReceiveByte:12864 : */unsigned char ReceiveByte(void)unsigned char i,temp1,temp2;temp1=temp2=0;STD_IN; /for(i=0;i8;i+)temp1=temp11;SCLK_L;NOP();NOP();SCLK_H;NOP();NOP(); SCLK_L;if(STD_IN_DATE) temp1+;/std1for(i=0;i8;i+)temp2=temp2MCUdo SendByte(0xfc); /? /1111 1100,RW(1),RS(0),0while(0x80&ReceiveByte();/RS=0/* : WriteCommand: unsigned char Cbyte : : Cbyte */void WriteCommand( unsigned char Cbyte )CS_H;CheckBusy();SendByte(0xf8);/11111 00 0,RW(0),RS(0),0delayms(10);SendByte(0xf0&Cbyte);/4delayms(10);SendByte(0xf0&Cbyte4);/CS_L;/* */void WriteData( unsigned char Dbyte )CS_H;CheckBusy();SendByte(0xfa); /11111 01 0,RW(0),RS(1),0delayms(10);SendByte(0xf0&Dbyte);delayms(10);SendByte(0xf0&Dbyte4);CS_L;/* */void PutChar(unsigned char row,unsigned char col,unsigned char puts) WriteCommand(0x30);/0x34WriteCommand(AC_TABLE8*row+col);WriteData(puts);/1void PutStr(unsigned char row,unsigned char col,unsigned char *puts) WriteCommand(0x30);/0x34WriteCommand(AC_TABLE8*row+col);while(*puts != 0)if(col=8)/col=0;row+;if(row=4)/row=0;WriteCommand(AC_TABLE8*row+col);WriteData(*puts);/1puts+;/1if(*puts != 0)WriteData(*puts);puts+;/1col+;/1 /* */void PutNum(uchar row,uchar col,uchar number)PutChar(row,col,number+48); /,0-9ASCII48-57/void Put2Num(uchar row,uchar col,uchar number)PutNum(row,col,number/10); /PutNum(row,col+1,number%10); /void Put4Num(uchar row,uchar col,uint number)PutNum(row,col,number/1000); /PutNum(row,col+1,number/100%10); /PutNum(row,col+2,number/10%10); /PutNum(row,col+3,number %10); /22void PutFloat1(uchar row,uchar col,float number) uchar shi,ge,shif,baif;shi=(uint)number)/10;ge=(uint)number)%10;shif=(uchar)(uint)(number*10)%10);baif=(uchar)(uint)(number*100)%10);if(shi=0)PutChar(row,col, );else PutNum(row,col,shi);PutNum(row,col+1,ge);PutChar(row,col+2,.);PutNum(row,col+3,shif);PutNum(row,col+4,baif);/13void PutFloat2(uchar row,uchar col,float number) uchar ge,shif,baif,qianf;ge=(uint)number)%10;shif=(uchar)(uint)(number*10)%10);baif=(uchar)(uint)(number*100)%10);qianf=(uchar)(uint)(number*1000)%10);PutNum(row,col,ge);PutChar(row,col+1,.);PutNum(row,col+2,shif);PutNum(row,col+3,baif);PutNum(row,col+4,qianf);/* */void Location_xy_12864(unsigned char x,unsigned char y)switch(x)case 0:x=0x80;break;case 1:x=0x90;break;case 2:x=0x88;break;case 3:x=0x98;break;default:x=0x80;y=y&0x07;WriteCommand(0x30);WriteCommand(y+x);WriteCommand(y+x);/?/* */void LcmClearTXT( void )unsigned char i;WriteCommand(0x30);/WriteCommand(0x80);/DDRAMAC80for(i=0;i64;i+) / 0X206416X480-88WriteData(0x20); /?/90-98.88-8F98-9FLocation_xy_12864(0,0);/ /* */void LcmClearBMP( void )unsigned char i,j;WriteCommand(0x34);/DL= 1,8BIT MPURE = 1,WriteCommand(0x36);/,ONfor(i=0;i32;i+)WriteCommand(0x80|i);/Y0-64,WriteCommand(0x80);/,RAMfor(j=0;j32;j+) /X80-98,WriteData(0);/ 0xff, F/ 128/8=16J16/* */void PutBMP(_flash unsigned char * puts) unsigned int x=0,y=0;unsigned char i,j;WriteCommand(0x34);WriteCommand(0x36);for(i=0;i32;i+) / 64WriteCommand(0x80|i); / WriteCommand(0x80); / for(j=0;j16;j+) / 0xff, F / 128/8=16J16 WriteData(putsx); x+;/PIC y=x-16; for(j=0;j16;j+) WriteData(putsy+512); y+; /* lcd*/void LcmInit( void ) DATE_DDR_out;/ rst_clear; NOP();/ rst_set; psb_set; WriteCommand(0x30);/Function set WriteCommand(0x03);/Function setODDRAM”AC00HK_cKDDRAM WriteCommand(0x0c);/Display ON/OFF controlB_/P ,D=1: wON,off,off WriteCommand(0x01);/Display clear DDRAM M 20HKO DDRAM ”AC00H WriteCommand(0x06);/Entry mode setYxcrO,/,DDRAM ”AC1,void display_welcome(void)LcmClearTXT();LcmClearBMP();PutBMP(bmp8);delay(1000);PutStr(1,2,);delay(2000);PutStr(1,2, 0-13v );delay(2000);PutStr(1,2,);delay(2000);PutStr(1,2,by);delay(2000);LcmClearTXT();LcmClearBMP(); void display_state(uint voltage) float vtemp=0,itemp=0;vtemp=(float)voltage;vtemp=vtemp*13.00/1024.00;/1024/PutNum(0,0,3);/Put2Num(1,0,23);/Put4Num(2,0,2343);PutStr(0,0,);PutFloat1(1
展开阅读全文