#include<reg52.h> typedef unsigned char uint8; typedef unsigned int uint16; sbit dula=P2^6; sbit wela=P2^7; sbit LCDEN = P3^4; sbit RS = P3^5; sbit RW = P3^6; sbit BUSY = P0^7; //繁忙检测标志 void _delay_ms(uint16 delaytime); //延时函数 void LCD1602_Wait(); //繁忙检测 void LCD1602_Write_Cmd(uint8 w_cmd); //写命令 void LCD1602_Write_Byte(uint8 w_byte); //写数据 void LCD1602_Init(); //初始化1602 LCD void LCD1602_Roll_String(uint8 *str); //显示滚动字幕 void main() { uint8 str[] = "Fuck you"; LCD1602_Init(); while (1) { LCD1602_Roll_String(str); } } void _delay_ms(uint16 delaytime) { uint8 i = 0; while (delaytime--) { for (i=0; i < 112; i++) ; } } void LCD1602_Wait() { do { RS = 0; RW = 1; LCDEN = 0; LCDEN = 1; } while (BUSY); LCDEN = 0; } void LCD1602_Write_Cmd(uint8 w_cmd) { LCD1602_Wait(); RS = 0; RW = 0; P0 = w_cmd; LCDEN = 0; _delay_ms(5); LCDEN = 1; _delay_ms(5); LCDEN = 0; } void LCD1602_Write_Byte(uint8 w_byte) { LCD1602_Wait(); RS = 1; RW = 0; P0 = w_byte; LCDEN = 0; _delay_ms(5); LCDEN = 1; _delay_ms(5); LCDEN = 0; } void LCD1602_Init() { dula=0; wela=0; //关数码管 LCD1602_Write_Cmd(0x38); //16X2显示 5X7点阵显示 8位数据接口 LCD1602_Write_Cmd(0x08); //显示关闭 LCD1602_Write_Cmd(0x01); //清屏 LCD1602_Write_Cmd(0x06); //显示光标移动设置 LCD1602_Write_Cmd(0x0c); //显示开及光标设置 } void LCD1602_Roll_String(uint8 *str) { static uint8 start = 0x80; //字幕起始位置 static uint8 offset = 0; //光标相对起始位置的偏移 static uint8 cursor = 0x80; //光标位置 LCD1602_Write_Cmd(0x01); //清屏 while (str[offset] != '/0') //显示字幕 { cursor = 0x80+(start+offset)%0x10; //取 模以防越界 LCD1602_Write_Cmd(cursor); LCD1602_Write_Byte(str[offset++]); } offset = 0; start++; if (start == 0x90) //滚动出边界 { start = 0x80; //重新从头开始滚动 } _delay_ms(200); }
因篇幅问题不能全部显示,请点此查看更多更全内容
大桥遇难公交司机凌晨4点出门上班 发班路上出事了
苏州一高架路面结冰上百辆车相撞 事故导致部分人员轻伤
各地解锁多种玩法“闹”元宵 “跨城赏灯”流行了起来
酸奶界面临集体降价,高价酸奶的神话或已成历史
怀疑对方AI换脸可以让对方摁鼻子 真人摁下去鼻子会变形
女子野生动物园下车狼悄悄靠近 后车司机按喇叭提醒
睡前玩8分钟手机身体兴奋1小时 还可能让你“变丑”
惊蛰为啥吃梨?倒春寒来不来就看惊蛰
男子高速犯困开智能驾驶出事故 60万刚买的奔驰严重损毁