基于单片机Amega16 avr数控直流电源的设计.doc
数控直流稳压电源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) 当输入交流电压为220v±10%时,输出电压在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 people's 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 <iom16v.h>#include <macros.h>#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<iom16v.h>#include<macros.h>#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&0x08±íʾ¶ÁÈ¡Êý¾Ý¿ÚPB3µÄÊýÖµ£¬¼´stdµÄ״̬/#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;i<t;i+)for(j=0;j<300;j+)NOP();/¶ÌÑÓʱ/*º¯ÊýÃû³Æ:SendByte()º¯Êý²ÎÊý:unsigned char Dbyteº¯Êý¹¦ÄÜ:Ïò12864·¢ËÍÒ»¸ö×Ö½Ú º¯ÊýÈë¿Ú:DbyteÀí½â12864¶¨×ø±êµÄ ·¢ËÍÒ»¸ö×Ö½Ú*/void SendByte(unsigned char Dbyte)unsigned char i;STD_OUT; /Êý¾Ý¿ÚÉ趨ΪÊä³öfor(i=0;i<8;i+)SCLK_L;NOP();NOP(); if(Dbyte&0x80) STD_H;/дÈë1 else STD_L;/дÈë0 SCLK_H;NOP();NOP();SCLK_L;Dbyte=Dbyte<<1;/´Ó¸ßλдµ½µÍλ/8´Î´®Ðз¢ËÍ/* º¯ÊýÃû³Æ: ReceiveByteº¯Êý²ÎÊý:ÎÞº¯Êý¹¦ÄÜ:´Ó12864 ½ÓÊÕÒ»¸ö×Ö½Ú º¯ÊýÈë¿Ú:ÎÞ */unsigned char ReceiveByte(void)unsigned char i,temp1,temp2;temp1=temp2=0;STD_IN; /Êý¾Ý¿ÚÉ趨ΪÊäÈë¶ÁÈ¡for(i=0;i<8;i+)temp1=temp1<<1;SCLK_L;NOP();NOP();SCLK_H;NOP();NOP(); SCLK_L;if(STD_IN_DATE) temp1+;/stdΪ¸ß£¬Ôò¼Ó1²Ù×÷for(i=0;i<8;i+)temp2=temp2<<1;SCLK_L;NOP();NOP();SCLK_H;NOP();NOP();SCLK_L;if(STD_IN_DATE) temp2+;/½ÓÊÕÁ½´Î£¬·Ö±ðÈ¥²»Í¬µÄ¸ßµÍËÄλ×é³ÉÒ»¸öÊý¾Ýreturn (0xf0&temp1)+(0x0f&temp2);/ £¿/* º¯ÊýÃû³Æ: CheckBusyº¯Êý²ÎÊý:ÎÞº¯Êý¹¦ÄÜ: ¼ì²éæ״̬º¯ÊýÈë¿Ú:ÎÞ */void CheckBusy( void )/RW=1 ±íʾÊý¾Ý´ÓLCD->MCUdo 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);/·¢ËÍÇ°4λdelayms(10);SendByte(0xf0&Cbyte<<4);/·¢ËͺóËÄλ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&Dbyte<<4);CS_L;/* ÏÔʾ×Ö·ûºÍ×Ö·û´®*/void PutChar(unsigned char row,unsigned char col,unsigned char puts) WriteCommand(0x30);/»ù±¾Ö¸Á£¬Èô0x34ΪÀ©³äÖ¸ÁWriteCommand(AC_TABLE8*row+col);WriteData(puts);/·¢ËÍÒ»¸ö×Ö·û£¬Ò»¸ö×Ö·û1¸ö×Ö½Úvoid PutStr(unsigned char row,unsigned char col,unsigned char *puts) WriteCommand(0x30);/»ù±¾Ö¸Á£¬Èô0x34ΪÀ©³äÖ¸ÁWriteCommand(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);/·¢ËÍÒ»¸ö×Ö·û£¬Ò»¸ö×Ö·û1¸ö×Ö½Úputs+;/µØÖ·¼Ó1if(*puts != '0')WriteData(*puts);puts+;/µØÖ·¼Ó1col+;/ºº×ÖµØÖ·¼Ó1 /* ÏÔʾÊý×Ö*/дһλÊý×Övoid PutNum(uchar row,uchar col,uchar number)PutChar(row,col,number+48); /дÈëÊý×Ö,Êý×Ö0-9¶ÔÓ¦ASCIIÂë48-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); /д¸öλ/дСÊý£¬ÕûÊý²¿·ÖÓÐ2λ£¬Ð¡Êý²¿·ÖÓÐ2λvoid 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