原创 51单片机0-30v 4A数控电源

2023-4-27 20:12 913 5 5 分类: MCU/ 嵌入式
分享一个不错的51单片机0-30v 4A数控电源.就是成本有点高!两路输出:1:0-30V/4A   2: 5V/1.5A(固定输出)

电压分辨率0.458mV,电流分辨率0.076mA
电压步进0.0073V,实际用的是0.1V步进调节

在制作中发现;C37极性画反了!还有就是复位电路是51和AVR都兼容的,不能把四个原件都焊接上去,
用什么芯片就焊接什么样的复位电路 !特此告知!

 

单片机源程序:
  1. #include"reg52.h"
  2. #include"math.h"
  3. #include"intrins.h"
  4. #include"function.h"

  5. #define DB P0

  6. sbit RS = P1^4;
  7. sbit RW = P1^5;
  8. sbit E  = P1^6;

  9. uchar code logo[] = {

  10. /*--  调入了一幅图像:I:\液晶屏BMP图\菜单.bmp  --*/
  11. /*--  宽度x高度=128x64  --*/
  12. 0x00,0x00,0x00,0x20,0x20,0x08,0x20,0x20,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  13. 0x00,0x00,0x00,0x20,0x17,0xFC,0x13,0xF0,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
  14. 0x00,0x00,0x78,0x20,0x50,0x08,0x12,0x20,0x24,0x90,0x00,0x00,0x00,0x00,0x00,0x00,
  15. 0x10,0x00,0x4B,0xFC,0x40,0x08,0x02,0x20,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
  16. 0x70,0x00,0x48,0x20,0x47,0xC8,0x02,0x1C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  17. 0x10,0x00,0x48,0x20,0x44,0x48,0xF4,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
  18. 0x10,0x00,0x79,0x20,0x44,0x48,0x1B,0xF0,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19. 0x10,0x00,0x48,0xA0,0x47,0xC8,0x11,0x10,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  20. 0x10,0x00,0x48,0xA0,0x44,0x48,0x11,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  21. 0x10,0x00,0x48,0x20,0x44,0x48,0x14,0xA0,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  22. 0x10,0x00,0x78,0x20,0x47,0xC8,0x18,0x40,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  23. 0x10,0x60,0x48,0x20,0x40,0x08,0x10,0xA0,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  24. 0x7C,0x60,0x40,0xA0,0x40,0x28,0x03,0x1C,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  25. 0x00,0x00,0x00,0x40,0x40,0x10,0x0C,0x08,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
  26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  27. 0x00,0x00,0x00,0x10,0x00,0x10,0x20,0x20,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  28. 0x00,0x00,0x1F,0xF8,0x3F,0xF8,0x13,0xF0,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
  29. 0x00,0x00,0x10,0x10,0x00,0x00,0x12,0x20,0x24,0x90,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x3C,0x00,0x1F,0xF0,0x00,0x00,0x02,0x20,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x42,0x00,0x10,0x10,0x00,0x08,0x02,0x1C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x42,0x00,0x1F,0xF0,0x7F,0xFC,0xF4,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x02,0x00,0x10,0x10,0x01,0x00,0x1B,0xF0,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x04,0x00,0x04,0x80,0x09,0x40,0x11,0x10,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x08,0x00,0x44,0x88,0x09,0x20,0x11,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x10,0x00,0x24,0x90,0x11,0x10,0x14,0xA0,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  37. 0x20,0x00,0x14,0xA0,0x21,0x08,0x18,0x40,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x42,0x60,0x14,0xC0,0x41,0x08,0x10,0xA0,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x7E,0x60,0x04,0x88,0x05,0x00,0x03,0x1C,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0xFF,0xFC,0x02,0x00,0x0C,0x08,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  42. 0x00,0x00,0x08,0x40,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  43. 0x00,0x00,0x1C,0x40,0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44. 0x00,0x00,0xF0,0x40,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x3C,0x00,0x11,0x50,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x42,0x00,0xFD,0x48,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x42,0x00,0x11,0x44,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0x04,0x00,0x32,0x44,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49. 0x18,0x00,0x3A,0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50. 0x04,0x00,0x52,0x48,0x09,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x02,0x00,0x50,0x10,0x18,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52. 0x42,0x00,0x90,0x20,0x28,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53. 0x42,0x60,0x10,0x40,0xC9,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  54. 0x3C,0x60,0x11,0x80,0x0A,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  55. 0x00,0x00,0x16,0x00,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  56. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  57. 0x00,0x00,0x20,0x08,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  58. 0x00,0x00,0x17,0xFC,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  59. 0x00,0x00,0x48,0x08,0x3C,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60. 0x08,0x00,0x42,0x08,0x41,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x08,0x00,0x5F,0xE8,0x41,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62. 0x18,0x00,0x42,0x08,0xF9,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63. 0x28,0x00,0x4F,0xC8,0xA1,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64. 0x48,0x00,0x4A,0x48,0x21,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x48,0x00,0x4A,0x48,0xFD,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x7E,0x00,0x4A,0x48,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x08,0x00,0x4A,0xC8,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x08,0x60,0x42,0x08,0x28,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x1E,0x60,0x42,0x28,0x30,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x40,0x10,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  76.                      };

  77. /************************************************************************************
  78.                    查忙函数         
  79. ************************************************************************************/
  80. void busy(void)//RS=0;RW=1;wait=0闲;wait!=0忙
  81. {
  82.     uchar wait;
  83.     RS = 0;
  84.     RW = 1;
  85.     E = 1;
  86.     for(;;)
  87.     {
  88.         wait = DB;
  89.         wait &= 0x80;
  90.         if(wait == 0)break;
  91.     }
  92.     E = 0;
  93. }

  94. /************************************************************************************
  95.                    写指令函数         
  96. ************************************************************************************/
  97. void w_code(uchar c)//RS=0;RW=0;E下降沿
  98. {
  99.     busy();
  100.     RS = 0;
  101.     RW = 0;
  102.     DB = c;
  103.     E = 1;
  104.     E = 0;
  105.     DB = 0xff;
  106. }

  107. /************************************************************************************
  108.                    写数据函数        
  109. ************************************************************************************/
  110. void w_data(uchar d)//RS=1;RW=0;E下降沿
  111. {
  112.     busy();
  113.     RS = 1;
  114.     RW = 0;
  115.     DB = d;
  116.     E = 1;
  117.     E = 0;
  118.     DB = 0xff;
  119. }

  120. /************************************************************************************
  121.                          读数据函数         
  122. ************************************************************************************/
  123. uchar r_data(void)//RS=1;RW=1;E下降沿
  124. {
  125.     uchar rd_lcd;
  126.     busy();
  127.     RS = 1;
  128.     RW = 1;
  129.     E = 1;
  130.     rd_lcd = DB;
  131.     E = 0;
  132.          return rd_lcd;
  133. }

  134. /************************************************************************************
  135.                    写DGRAM:x_lcd横坐标,y_lcd纵坐标         
  136. ************************************************************************************/
  137. void address(uchar x_lcd,uchar y_lcd)//
  138. {
  139.     w_code(y_lcd);//垂直坐标
  140.     w_code(x_lcd);//水平坐标
  141. }

  142. /************************************************************************************
  143.                    初始化液晶屏
  144.                                    0:字库  1:绘图      
  145. ************************************************************************************/
  146. void  lcd_rst(bit a)
  147. {  
  148.     if(a)
  149.         {
  150.         w_code(0x01);//   清屏  
  151.         w_code(0x32);//   功能设置---8BIT控制界面,绘图显示ON  
  152.         w_code(0x36);//   功能设置---8BIT控制界面,扩充指令集  
  153.         }
  154.         else
  155.         {
  156.         w_code(0x30);// 功能设置---8BIT控制界面,基本指令集
  157.         w_code(0x0c);//显示打开,光标关,反白显示关
  158.         w_code(0x01);// 清除屏幕显示,将DDRAM的地址计数器归零
  159.         }
  160. }

  161. /************************************************************************************
  162. ---------------------------写整屏点阵数据
  163. ---------------------------x :图像数据的起始地址        
  164. ************************************************************************************/

  165. void  write_lcd_full(uint x )
  166. {
  167.       
  168.           uchar  i,j,a;
  169.           j = 0x80; //Y地址寄存器   
  170.           for(a = 0;a < 32;a++)
  171.                   {
  172.                 w_code(j);
  173.                 j++;
  174.                 w_code(0x80);//X地址寄存器
  175.                   for(i = 0;i < 16;i ++)
  176.                           {
  177.                         w_data(logo[x]);
  178.                         x++;
  179.                         }
  180.                 }

  181.           j = 0x80; //Y地址寄存器  
  182.           for(a = 0;a < 32;a++)
  183.                   {
  184.                 w_code(j);
  185.                 j++;
  186.                 w_code(0x88);//X地址寄存器
  187.                   for(i = 0;i < 16;i ++)
  188.                           {
  189.                         w_data(logo[x]);
  190.                         x++;
  191.                         }
  192.                 }
  193. }
复制代码

作者: 小羡, 来源:面包板社区

链接: https://mbb.eet-china.com/blog/uid-me-4026945.html

版权声明:本文为博主原创,未经本人允许,禁止转载!

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
5
关闭 站长推荐上一条 /3 下一条