找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1511|回复: 0
收起左侧

51单片机+1602函数 Proteus仿真

[复制链接]
ID:891089 发表于 2021-3-14 09:05 | 显示全部楼层 |阅读模式
无标题.png

单片机源程序如下:
  1. /*---------------------------------------------------------------------
  2.                          LCD1602.C文件 LCD1602的函数  
  3. ----------------------------------------------------------------------*/

  4. #include "hardware.h"
  5. #include "lcd1602.h"

  6. void LCD_check_busy(void)   //检测LCD状态,看它是不是还在忙呢
  7. {
  8. while(1)
  9.   {
  10.    LCD_EN=0;
  11.    LCD_RS=0;
  12.    LCD_RW=1;
  13.    LCD_DATA=0xff;
  14.    LCD_EN=1;
  15.    if(!LCD_BUSY)break;
  16.   }
  17. LCD_EN=0;
  18. }

  19. void LCD_cls(void)          //LCD清屏
  20. {

  21. LCD_check_busy();
  22. LCD_RS=0;
  23. LCD_RW=0;
  24. LCD_DATA=1;
  25. LCD_EN=1;
  26. LCD_EN=0;

  27. }

  28. void LCD_write_instruction(unsigned char LCD_instruction)   //写指令到LCD
  29. {
  30.   LCD_check_busy();
  31. LCD_RS=0;
  32. LCD_RW=0;

  33. LCD_DATA=LCD_instruction;
  34. LCD_EN=1;
  35. LCD_EN=0;
  36. }

  37. void LCD_write_data(unsigned char LCD_data)      //输出一个字节数据到LCD
  38. {
  39.   LCD_check_busy();
  40. LCD_RS=1;
  41. LCD_RW=0;

  42. LCD_DATA=LCD_data;
  43. LCD_EN=1;
  44. LCD_EN=0;
  45. }

  46. void LCD_set_position(unsigned char x)            //LCD光标定位到x处
  47. {
  48. LCD_write_instruction(0x80+x);
  49. }

  50. /*
  51. void LCD_go_home(void)                         //LCD光标归位
  52. {
  53. LCD_write_instruction(LCD_GO_HOME);
  54. }
  55. */

  56. void LCD_printc(unsigned char lcd_data)          //输出一个字符到LCD
  57. {
  58. LCD_write_data(lcd_data);
  59. }

  60. void LCD_prints(unsigned char *lcd_string)       //输出一个字符串到LCD
  61. {
  62. unsigned char i=0;
  63. while(lcd_string[i]!=0x00)
  64.   {
  65.    LCD_write_data(lcd_string[i]);
  66.    i++;
  67.   }
  68. }

  69. void LCD_initial(void)                        //初始化LCD
  70. {
  71. LCD_write_instruction(LCD_AC_AUTO_INCREMENT|LCD_MOVE_DISENABLE);
  72. LCD_write_instruction(LCD_DISPLAY_ON|LCD_CURSOR_OFF);
  73. LCD_write_instruction(LCD_DISPLAY_DOUBLE_LINE);
  74. LCD_cls();
  75. }
复制代码

所有资料51hei提供下载:
项目.zip (73.85 KB, 下载次数: 17)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表