74LS165,74ls165是八位并行输入/串行输出移位寄存器当1脚为低电平时,将输入数据D0 - D7存入Q0 - Q7,数据存入后,使1脚为高电平,DS10脚=0, /CE15脚=0, CP2脚的8个时钟脉冲就能将并行数据从
Q7=9脚,串行移出 /Q7=7脚移出的数据是反相的
74LS165也 是位串行移位寄存器,时钟受控时,数据从QA向QH转移。八个单独的直接数据输入端使对每一 级的并行输入存取得以实现,直接数据输入端由移位/负载输入端的低电平赋能。这种寄存器也具有门控时 钟输入端和第八位互补输出端的特点。为使传输线效应变得最小,输入都是二极管钳位,因而简化了系统 设计。
时钟控制是通过一个 2 输入正或非门来实现的,这使一个输入羰可用作时钟禁止功能输入端。保持两 个时钟输入端的任何一个为高电平,则禁止时钟控制。保持任何一个时钟输入端为低电平,而移位/负载输 入端为高电平,则使另一个时钟输入端赋能,仅在这个时钟输入端为高电平时,时钟禁止输入端才应被变 到高电平,只要移位/负载输入为高电平就禁止并行输入。并行输入端的数据在移位/负载输入端从高电平 到低电平跃变时直接输入寄存器,而与时钟、时钟禁止或串行输入端三者的电平无关
要等到所有的数据都输入了才会一位一位的串行输出哈,在并行和串行输出端只有一个时钟有效,如果并行输出时钟有效,串行输出端就没有输出了!
你可以在>
可以利用print函数或者sprint函数
程序如下:
#include "reg52h" //此头文件中定义了单片机的一些特殊功能寄存器
typedef unsigned int u16;
typedef unsigned char u8;
void UsartInit()
{
SCON=0X50; //0101 000设置串行口控制寄存器sm0,sm1为01,即为工作方式1
TMOD=0X20; //设置计数器
PCON=0X80; //定义PCON寄存器中的SMOD=1,波特率加倍
TH1=0XF3; //计数器初始值设置,注意波特率是4800的,当然大家可以改
TL1=0XF3;
EA=1; //打开总中断 根据需要
ES=1; //打开中断允许中的串行口中断允许
TR1=1; //打开计数器
TI = 1;//如果使用print函数,TI一定要是1 否则 删掉该句
}
void main()
{
u16 Val;
UsartInit();
while(1)
{ Val = GetSensor();
printf("%d",Val;) //printf中一定要用u16的 不能用u8 这样就直接将数字格式化为ascii
}
}
主要程序语句如下:
SM1=0; SM0=0;//串口工作方式0,移位寄存器方式
TMOD=0X20;//定时器1工作方式2,自动重装模式
TH1=//装入初值
TL1=//装入初值
TR1=1;//启动定时器
while(1)
{
a=//小数点的代码是 0x80或0x7f
TI=0;
sbuf=a;//发送
while(!TI);
P3^4=1;//假设是共阳数码管
delay_ms(5);
P3^4=0;
a=//个位数的代码,或者查表
TI=0;
sbuf=a;//发送
while(!TI);
P3^5=1;
delay_ms(5);
P3^5=0;
}
//LCD12864字库系列(控制器ST7920A),单片机:89S52,晶振:12M,
//串口连接 与 并口连接 ( 串口时 屏蔽 并行模块)
//并行连接方式,P20-RS,P21-RW,P22-E
#include<reg52h>
#include <intrinsh>
sbit RS=P3^2; //串口时为CS
sbit RW=P3^1; //串口为SID
sbit E=P3^0; //串口为时钟SCLK
sbit stop=P2^2;
sbit PSB=P3^4;
sbit REST=P3^3;
//以下是用<at89x51h>头文件的定义
/
#define RS P2_0
#define RW P2_1 //定义引脚
#define E P2_2
#define PSB P2_3
#define REST P2_4
#define Data P1
#include<at89x51h>
/
#define BF 0x80 //用于检测LCM状态字中的Busy标识
typedef unsigned int Uint;
typedef unsigned char Uchar;
//字符串例子
//"F1--English",也可以往里面写入汉字码,一个汉字由两个码组成
const Uchar F1English[]={0x46,0x31,0x2d,0x2d,0x45,0x6e,0x67,0x6c,0x69,0x73,0x68,0x00};
const Uchar lengthF1=6; //字符串长度
//汉字,直接可以写入字形
unsigned char code uctech[] = {"有限公司"};
const Uchar lengthCF3=8;
Uchar code TAB1[]={
/-- 调入了一幅图像:D:\公司的文件\程序\未命名11bmp --/
/-- 宽度x高度=128x64 --/
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x05,0xAE,0x90,0x00,0x00,0x00,0x00,0x00,
0x95,0x55,0x48,0x80,0x00,0x00,0x00,0x00,
0x2B,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xA8,0x00,0x22,0x15,0x20,0x00,0x00,0x00,
0x97,0xFB,0x00,0x00,0x00,0x00,0x00,0x00,
0x45,0x55,0x08,0xA0,0x00,0x00,0x00,0x0A,
0x6F,0xF4,0x00,0x00,0x00,0x00,0x00,0x00,
0xB2,0x80,0x40,0x00,0x04,0x40,0x00,0x00,
0xBA,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x4D,0x55,0x15,0x15,0x20,0x00,0x00,0x95,
0xD5,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xE8,0x40,0x40,0x00,0x00,0x00,0x4A,
0xAA,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x2A,0x00,0x40,0x00,0x00,0x15,
0x54,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFD,0xD0,0xAA,0x01,0x00,0x00,0x25,
0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xB6,0x00,0x10,0x00,0x01,0x4A,
0x49,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFD,0xE8,0x40,0x00,0x00,0x11,
0x00,0x24,0x84,0x00,0x00,0x00,0x00,0x00,
0xAB,0xFF,0xFF,0x55,0x00,0x00,0x00,0x24,
0x02,0x49,0x5E,0xA0,0x00,0x00,0x00,0x00,
0x84,0xBF,0xFF,0xF4,0x88,0x00,0x00,0x00,
0x10,0x05,0xFF,0xF4,0x00,0x00,0x00,0x00,
0x29,0x0B,0xFF,0xFA,0x20,0x00,0x00,0x00,
0x02,0xBF,0xFF,0xFC,0x00,0x00,0x00,0x00,
0x44,0xA0,0x57,0xFD,0x80,0x00,0x00,0x00,
0x08,0x5F,0xFF,0xFF,0x80,0x00,0x00,0x00,
0x91,0x0A,0xAA,0xF6,0x50,0x00,0x00,0x00,
0x41,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,
0x44,0xA0,0x01,0x1B,0x84,0x00,0x00,0x00,
0x26,0xFF,0xFF,0xFF,0x90,0x00,0x00,0x00,
0x11,0x0A,0xAA,0x6D,0x68,0x00,0x00,0x00,
0x0B,0xFB,0xFF,0xEF,0xE0,0x00,0x00,0x00,
0xC4,0xA0,0x01,0x02,0x80,0x00,0x00,0x00,
0x43,0xF1,0xFE,0x63,0xF0,0x00,0x00,0x00,
0x15,0x55,0x54,0x55,0x6A,0x00,0x00,0x00,
0x9F,0xE3,0xFC,0x87,0x38,0x00,0x00,0x00,
0xCA,0xAB,0x91,0x00,0x90,0x00,0x00,0x00,
0x07,0xC1,0xFA,0x2A,0x80,0x00,0x00,0x00,
0x25,0xFF,0xFE,0x95,0x2A,0x00,0x00,0x00,
0x2F,0x13,0xFE,0xFC,0x10,0x00,0x00,0x00,
0x95,0xFF,0xFF,0xC0,0x50,0x00,0x00,0x00,
0x0F,0x41,0xFF,0xF3,0x80,0x00,0x00,0x00,
0x4F,0xFF,0xFF,0xF9,0x2A,0x00,0x00,0x00,
0x9F,0x08,0xFF,0xD4,0x00,0x00,0x00,0x00,
0xB3,0xFF,0xFF,0xFE,0x54,0x80,0x00,0x00,
0x1E,0xA0,0x7F,0xA0,0x00,0x00,0x00,0x00,
0x5F,0xFE,0x7F,0xFE,0xAA,0x00,0x00,0x00,
0x5F,0x57,0xFE,0x00,0x00,0x00,0x00,0x00,
0xAF,0xFD,0x7F,0xFF,0x94,0x80,0x00,0x00,
0x1F,0xFE,0xE8,0x00,0x00,0x00,0x00,0x00,
0x7F,0xFA,0x7F,0x5F,0xCA,0x00,0x00,0x00,
0x3F,0x55,0x00,0x00,0x00,0x00,0x00,0x00,
0xAF,0xF1,0x7F,0xDE,0xF5,0x40,0x00,0x00,
0x1A,0xA0,0x80,0x00,0x00,0x00,0x00,0x00,
0xDF,0xF2,0x3F,0xFC,0xC2,0x00,0x00,0x00,
0x50,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x2F,0xFA,0xBF,0xFF,0xF4,0xA0,0x00,0x00,
0x05,0x42,0x00,0x00,0x00,0x00,0x00,0x00,
0x97,0xFE,0x3F,0xFF,0xE3,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x68,0xFF,0xDF,0xD5,0x78,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x5F,0xFF,0x48,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD0,0xAA,0xF4,0xA0,0xAA,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0A,0x45,0x09,0x05,0x11,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA1,0x28,0xA0,0x00,0x44,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x42,0x04,0x52,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA5,0x09,0x51,0x00,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x50,0x04,0x4A,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xAA,0x05,0x50,0x21,0x48,0x20,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x90,0x02,0x84,0x12,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xD4,0x05,0x48,0x10,0x48,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x81,0x20,0x00,0x02,0x02,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA4,0x84,0x92,0x48,0x94,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x48,0x10,0x00,0x00,0x21,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//这个是在串口时指令和数据之间的延时
/
void delay10US(Uchar x)
{
Uchar k;
for(k=0;k<x;k++);
}
/
const Uchar delay=250; //延时时间常数
static void Wait1ms(void)//延迟1 ms
{
Uchar cnt=0;
while (cnt<delay) cnt++;
}
//延迟n ms
void WaitNms(int n)
{
Uchar i;
for(i=1;i<=n;i++)
Wait1ms();
}
void stopint(void)//中断程序
{
if(stop==0)
while(1);
}
////
//以下是并口时才开的
//读忙标志,
void RDBF(void)
{
Uchar temp;
RS=0; // RS=0
RW=1; // RW=1
while(1)
{
P1=0xFF; //数据线为输入
E=1;
temp=P1;
E=0; // E=0
if ((temp&0x80)==0) break;
}
}
//写数据到指令寄存器
void WRCommand(Uchar comm)
{
RDBF();
RW=0;
P1=comm;
E=1;
E=0;
}
//写数据到数据寄存器
void WRData(Uchar TEMP)
{
RDBF();
RS=1;
RW=0;
P1=TEMP;
E=1;
E=0;
stopint();
}
/////////////////////////////////////////////////////////////////////////////////
//以下是串口时开的读写时序
/void SendByteLCD(Uchar WLCDData)
{
Uchar i;
for(i=0;i<8;i++)
{
if((WLCDData<<i)&0x80)RW=1;
else RW=0;
E=0;
E=1 ;
}
}
SPIWR(Uchar Wdata,Uchar WRS)
{
SendByteLCD(0xf8+(WRS<<1));
SendByteLCD(Wdata&0xf0);
SendByteLCD((Wdata<<4)&0xf0);
}
void WRCommand(Uchar CMD)
{
RS=0;
RS=1;
SPIWR(CMD,0);
delay10US(90);//89S52来模拟串行通信,所以,加上89S52的延时,
}
void WRData(Uchar Data)
{
RS=0;
RS=1;
SPIWR(Data,1);
}
/
//
//初始化LCD-8位接口
void LCDInit(void)
{ // PSB=0; //串口
PSB=1;//并口时选这个,上一行取消
REST=1;
REST=0;
REST=1;
WRCommand(0x30); //基本指令集,8位并行
WRCommand(0x06); //启始点设定:光标右移
WRCommand(0x01); //清除显示DDRAM
WRCommand(0x0C); //显示状态开关:整体显示开,光标显示关,光标显示反白关
WRCommand(0x02); //地址归零
}
//显示数组字符串(显示半宽字型168点阵)
void ShowQQChar(Uchar addr,Uchar english,Uchar count)
{
Uchar i;
WRCommand(addr); //设定DDRAM地址
for(i=0;i<count;)
{
WRData(english[i2]);
WRData(english[i2+1]);
i++;
}
}
//显示连续字串(半宽字符)
void ShowNUMChar(Uchar addr,Uchar i,Uchar count)
{
Uchar j;
for(j=0;j<count;)
{
WRCommand(addr); //设定DDRAM地址
WRData(i+j);
j++;
WRData(i+j);
addr++;
j++;
}
}
//自定义字符写入CGRAM
void WRCGRAM(Uchar data1,Uchar data2,Uchar addr)
{
Uchar i;
for(i=0;i<16;)
{
WRCommand(addr+i); //设定CGRAM地址
WRData(data1);
WRData(data1);
i++;
WRCommand(addr+i); //设定CGRAM地址
WRData(data2);
WRData(data2);
i++;
}
}
//显示自定义的字符,并把这个字符填满全屏1616
void ShowCGChar(Uchar addr,Uchar i)
{
Uchar j;
for(j=0;j<0x20;)
{
WRCommand(addr+j); //设定DDRAM地址
WRData(0x00);
WRData(i);
j++;
}
}
void CLEARGDRAM(void)
{
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<32;j++)
{
WRCommand(0x80+j);
WRCommand(0x80);//X坐标
for(i=0;i<32;i++)//
{
WRData(0x00);
}
}
}
//写入GDRAM 绘图,Y是Y绘图坐标,2个字节一行,CLONG是图形长度,以字节
//为单位;HIGHT是图形高度,TAB是图形数据表12864M的图形显示是相当于25632点阵
//由两屏12832上下两屏组成,同一行的下屏的头地址紧接上屏的未地址。
//绘图在串口输入时,会比在并口下的输入要慢一些
void WRGDRAM(Uchar Y1,Uchar clong,Uchar hight,Uchar TAB1)
{
Uint k;
Uchar j;
Uchar i;
WRCommand(0x34);
WRCommand(0x36);
for(j=0;j<hight;j++)//32
{ //先上半屏
WRCommand(Y1+j); //Y总坐标,即第几行
WRCommand(0x80);//X坐标,即横数第几个字节开始写起
for(i=0;i<clong;i++)//
{
WRData(TAB1[clongj+i]);
}
//后下半屏
for(k=0;k<clong;k++)//
{
WRData(TAB1[clong(j+hight)+k]);
}
}
}
void menu(void)
{
LCDInit();
ShowNUMChar(0x80,0x01,0x0f);//显示半宽特殊符号
ShowNUMChar(0x90,0x30,0x0f);//显示半宽0~数字标点
ShowNUMChar(0x88,0x41,0x0f);//显示半宽A~P大写
ShowNUMChar(0x98,0x61,0x0f);//显示半宽a~p小写
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
WRCGRAM(0xff,0x00,0x40);//写入横
WRCGRAM(0x00,0xff,0x50);//写入横2
WRCGRAM(0xaa,0xaa,0x60);//写入竖
WRCGRAM(0x55,0x55,0x70);//写入竖2
ShowCGChar(0x80,0x00);//显示横并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,02);//显示横2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,04);//显示竖并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,06);//显示竖2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
WRCGRAM(0x00,0x00,0x40);//清CGRAM1
WRCGRAM(0x00,0x00,0x50);//清CGRAM2
WRCGRAM(0xaa,0x55,0x40);//写入点
WRCGRAM(0x55,0xaa,0x50);//写入点2
ShowCGChar(0x80,00);//显示点并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowCGChar(0x80,02);//显示点2并填满
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
ShowQQChar(0x80,uctech,lengthCF3);//显示'有限公司',以下共四行
ShowQQChar(0x90,uctech,lengthCF3);
ShowQQChar(0x88,uctech,lengthCF3);
ShowQQChar(0x98,uctech,lengthCF3);
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
WRCommand(0x01); //清除显示DDRAM
}
void menu2(void)
{ CLEARGDRAM();
WRGDRAM(0x80,16,32,TAB1);
WaitNms(250); //等待时间
WaitNms(250); //等待时间
stopint();
}
//主函数
void main(void)
{
menu();//初始化及半宽字符和点横竖汉字扫描
menu2();//绘图显示
for(;;)
{;}
}
以上就是关于74LS165并行输入串行输出,判断高电平数量并且记录步进电机运行时间全部的内容,包括:74LS165并行输入串行输出,判断高电平数量并且记录步进电机运行时间、74HC595是不是串行移入之后马上串行输出如果并行输出时钟有效,串行输出端还有输出吗、求一段STC89C52单片机将数值通过串口输出的代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)