-
如何解决keil5编译但lcd12864显示汉字时乱码?求求了
[float=left][color=rgb(40, 40, 40)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "][size=16px][color=rgb(47, 47, 47)][size=14px][align=left]这是部分代码:[/align][align=left]#include
[/align] [align=left]#define uchar unsigned char // 以后unsigned char就可以用uchar代替[/align][align=left]#define uint unsigned int // 以后unsigned int 就可以用uint 代替[/align] [align=left]sbit LcdRs_P = P2^0; // 液晶的RS管脚 [/align][align=left]sbit LcdRw_P = P2^1; // 液晶的RW管脚 [/align][align=left]sbit LcdEn_P = P2^2; // 液晶的EN管脚[/align] [align=left]// 毫秒级的延时函数,time是要延时的毫秒数[/align] [align=left]void DelayMs(uint time)[/align][align=left]{[/align][align=left] uint i,j;[/align][align=left] for(i=0;i 19465浏览量 21回复量 关注量 -
如何解决keil5编译但lcd12864显示汉字时乱码? sos
[align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]这是部分代码:[/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]#include
[/font][/backcolor][/color][/align] [align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]#define uchar unsigned char // 以后unsigned char就可以用uchar代替[/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]#define uint unsigned int // 以后unsigned int 就可以用uint 代替[/font][/backcolor][/color][/align] [align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]sbit LcdRs_P = P2^0; // 液晶的RS管脚 [/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]sbit LcdRw_P = P2^1; // 液晶的RW管脚 [/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]sbit LcdEn_P = P2^2; // 液晶的EN管脚[/font][/backcolor][/color][/align] [align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]// 毫秒级的延时函数,time是要延时的毫秒数[/font][/backcolor][/color][/align] [align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]void DelayMs(uint time)[/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "]{[/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "] uint i,j;[/font][/backcolor][/color][/align][align=left][color=rgb(47, 47, 47)][backcolor=rgb(255, 255, 255)][font=微软雅黑, "] for(i=0;i 1929浏览量 0回复量 关注量 -
扎原因扎结果 sos
[b]//代码如下[/b] #include
#include //#include //#include #include #define SEG_BITSEL_PORT PORTD //位选端口 #define SEG_BITSEL_PORT_DIR TRISD //位选端口的方向寄存器 #define SEG_FONT_PORT PORTC //字形输出端口 #define SEG_FONT_PORT_DIR TRISC //字形输出端口的方向寄存器 #define DLY_MS 67 const char Seg7TableN[]={0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000010,0b11111000,0b10000000,0b10010000}; //__CONFIG(FOSC_HS & WDTE_ON & PWRTE_OFF & BOREN_ON & LVP_ON & CPD_OFF & WRT_OFF & CP_OFF); //__CONFIG (XT & WDTDIS & LVPDIS); unsigned int g_ADRTable[12] = {0,0,0,0,0,0,0,0,0,0,0 }; unsigned char g_Count=0; bit OverFlag = 0;//12位转换次数完成标志位清零; void delayms (int ms); void DisplayData (unsigned int iData); interrupt ISR (void) { if ( ADIE && ADIF ) { ADIF = 0; g_ADRTable[g_Count]=(((unsigned int)ADRESH)<<8)+ADRESL; g_Count++; if(g_Count==12) { g_Count =0; OverFlag=1;// } else { GO_DONE = 1;//启动AD } } else { while(1); } } void main(void) { //void DisplayData(); char i=0,j=0; int tmp = 0;// int adc_v = 0; TRISA0 = 1; SEG_BITSEL_PORT_DIR = 0;//位选端口的方向寄存器,确定输出端口 SEG_FONT_PORT_DIR = 0;//字形输出端口的方向寄存器,确定输出端口 ADFM = 1; PCFG3:PCFG0 = 0000; ADCON0 = 0B11000001; ADIE = 1; ADIF = 0; PEIE = 1; GIE = 1; for(i=0;i<15;i++) { } GO_DONE = 1; while(GO_DONE) { if(OverFlag==1) { for(i=0;i<12;i++)//冒泡法排序 { for(j=i+1;j<12;j++) { if(g_ADRTable[i] > g_ADRTable[j]) { tmp = g_ADRTable[i]; g_ADRTable[i] = g_ADRTable[j]; g_ADRTable[j] = tmp; } } } tmp = 0; for(i=2;i<10;i++) { tmp = tmp + g_ADRTable[i]; } tmp = tmp >>3;//将数按照 2进制像右移动.每向右移动一位,相当于 除2的n次幂 adc_v = tmp; adc_v = ((long)adc_v*5000/1023); OverFlag = 0; GO_DONE = 1; } DisplayData(adc_v); } } void DisplayData (unsigned int iData ) { char i=0,j=0;// char k = 0,NumStr[ 5 ]={0,0,0,0,0}; NumStr[1]=iData / 1000;//取整 NumStr[2]=iData % 1000/100; NumStr[3]=iData % 100/10; NumStr[4]=iData % 10; for(i=0;i<10;i++) { SEG_BITSEL_PORT = k =0X01; for(j=0;j<=4;j++) { SEG_BITSEL_PORT = k; if(j==1) { SEG_FONT_PORT = Seg7TableN[NumStr[1]]&0b01111111; } else { SEG_FONT_PORT = Seg7TableN[NumStr[j]]; } delayms(5); k = k <<1;//把1向左移1为显示 } } } void delayms (int ms) { int i=0,j =0; for(i=0;i < ms;i++) for(j =0; j < DLY_MS;j++) {;} } //仿真结果,单片机数码管显示全是0,与设计的测量电阻电压不对,希望大家来找茬,这原因与结果 1438浏览量 0回复量 关注量 -
点亮流水灯只能用延时函数吗?
本人用delay函数可以成功完成流水灯,但是用for却失败了,问了C语言老师,他也不清楚,请问该如何修改呢?谢谢。/*成功*/。 #include
#include #define uint unsigned int #define uchar unsigned char uchar temp; void delay(); void main() { temp=0xfe; P1=temp; while(1) { temp=_crol_(temp,1); delay(); P1=temp; } } void delay() { uint x,y; for(x=1000;x>0;x--) for(y=200;y>0;y--); } /*失败*/ #include #include sbit p1_1=P1^0; #define uchar unsigned char//宏定义 #define uint2 unsigned int uchar temp;//字符型,要8位的,uchar是8位的 unsigned int a; void delay(uint2); void main() { temp=0xfe; p1_1=temp; while(1) { temp=_crol_(temp,1); uint2 x,y; a=50000; p1_1=temp; while(a--); for(x=130;x>0;x--) for(y=452;y>0;y--); a=50000; p1_1=temp; while(a--); for(x=130;x>0;x--) for(y=452;y>0;y--); } } 27215浏览量 13回复量 关注量 -
为什么按下S5后定时器没有打开去掉nowshidu=dat_rd1*20就可以了
#include
#include"ds1302.h" #include"iic.h" sbit S7=P3^0; sbit S6=P3^1; sbit S5=P3^2; sbit S4=P3^3; unsigned char dat_rd2; unsigned char kaiguan=0; unsigned char shidu=50; //初始湿度 unsigned char nowshidu; //当前湿度 unsigned char code table[]={0xc0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E,0xbf,0x7f}; unsigned char write[]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; unsigned char read[]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d}; unsigned char Time[]={0x16,0x30,0x08,0x02,0x16,0x02,0x21}; void delayms(unsigned char x) { unsigned char i; while(x--) { for(i=0;i<113;i++); } } void select (unsigned char n) { switch(n) { case 4: P2=(P2&0x1f)|0x80; break; case 5: P2=(P2&0x1f)|0xa0; break; case 6: P2=(P2&0x1f)|0xc0; break; case 7: P2=(P2&0x1f)|0xe0; break; } } void guanbi() { select(5); P0=0x00; select(4); P0=0xff; } void DS1302_write() { unsigned char i; Ds1302_Single_Byte_Write(0x8e,0x00); for(i=0;i<7;i++) { Ds1302_Single_Byte_Write(write[i],Time[i]); } Ds1302_Single_Byte_Write(0x8e,0x80); } void DS1302_read() { unsigned char i; for(i=0;i<7;i++) { Time[i]=Ds1302_Single_Byte_Read(read[i]); } } void read_rd2() { IIC_Start(); IIC_SendByte(0x90); IIC_WaitAck(); IIC_SendByte(0x03); IIC_WaitAck(); IIC_Start(); IIC_SendByte(0x91); IIC_WaitAck(); dat_rd2=IIC_RecByte(); IIC_WaitAck(); IIC_Ack(0); IIC_Stop(); } void shuma(unsigned char pos,unsigned char date) { select(6); P0=0x01< shidu) { select(5); P0=0x40; } else if(nowshidu 2986浏览量 1回复量 关注量 -
求助,函数没写到主函数里,为什么能执行成功
void SMG_Play()该函数没写到主函数里,但是一个错误和警告都没有,而且该函数还执行成功了?为什么??求助 #include
#include unsigned char code SMG_Select_1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf,0x7f}; unsigned int temp=0; unsigned char c=0; unsigned char b=0; void SMG_Play(); void SCQ_Set(unsigned char a) { switch(a) { case 4:P2=(P2&0x1f)|0x80; break; case 5:P2=(P2&0x1f)|0xa0; break; case 6:P2=(P2&0x1f)|0xc0; break; case 7:P2=(P2&0x1f)|0xe0; break; case 0:P2=(P2&0x1f)|0x00; break; } } void Delay_1(unsigned int t) { while(t--); } void Delay_SMG(unsigned int t) { while(t--) { SMG_Play(); } } void SMG_Set(unsigned char num,unsigned char loc) { SCQ_Set(6); P0=0x01< >4); } void SMG_Play() { SMG_Set(SMG_Select_1[16],0); Delay_1(100);P0=0xff; SMG_Set(SMG_Select_1[0],1); Delay_1(100);P0=0xff; SMG_Set(SMG_Select_1[16],2); Delay_1(100);P0=0xff; SMG_Set(0xff,3); Delay_1(100);P0=0xff; SMG_Set(0xff,4); Delay_1(100);P0=0xff; SMG_Set(0xff,5); Delay_1(100);P0=0xff; SMG_Set(SMG_Select_1[temp/10],6); Delay_1(100);P0=0xff; SMG_Set(SMG_Select_1[temp%10],7); Delay_1(100);P0=0xff; } void main() { P2=0x80;P0=0xff; P2=0xa0;P0=0x00; //初始化 while(1) { DS18B20_Set(); } } 3841浏览量 3回复量 关注量 -
lcd1602滚动显示
[color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]#include
[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]typedef unsigned char uint8;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]typedef unsigned int uint16;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]sbit rs=P2^6;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]sbit rw=P2^5;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]sbit e=P2^7;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]uint8 a[16]="perchin designed";[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]uint8 b[27]="welcome to the world of mcu";[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]void delay(uint16 i) //1us[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]{[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] while(i--);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]}[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]void wrc(uint8 c)[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]{[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] delay(1000);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] rs=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] rw=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] P0=c;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=1;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] delay(10);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] /*[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] P0=c<<4;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=1;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;*/ //四位的LCD要加上[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]}[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]void wrd(uint8 dat)[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]{[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] delay(1000);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] rs=1;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] rw=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] P0=dat;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=1;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] delay(10);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] /*[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] P0=dat<<4;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=1;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] e=0;*/ //四位的LCD要加上[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] rs=0; [/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]}[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]void init()[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]{[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] delay(1000);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] /*wrc(0x32); [/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x28);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x28); */ //四位的LCD要加上[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x38);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x38);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x38); [/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x0c); [/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x01); [/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]}[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]void display()[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px]{[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] uint8 i;[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrc(0x00+0x80);[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] for(i=0;i<16;i++)[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] {[/size][/font][/backcolor][/color] [color=#4c4c4c][backcolor=rgb(255, 255, 255)][font="][size=16px] wrd(a[/size][/font][/backcolor][/color][color=rgb(76, 76, 76)][backcolor=rgb(255, 255, 255)][font="][size=16px]); } wrc(0x40+0x80); for(i=0;i<27;i++) { wrd(b); } wrc(0x07); //每写一个数据屏幕就要右移一位,就相对于数据来说就是左移了; while(1) { wrc(0x00+0x80); for(i=0;i<16;i++) { wrd(a); delay(30000); //如果不加这条延时语句的话滚动会非常快。 } } } void main() { init(); while(1) { display(); } } 请问下面这条语句怎样实现滚动 while(1) { wrc(0x00+0x80); for(i=0;i<16;i++) { wrd(a); delay(30000); //如果不加这条延时语句的话滚动会非常快。 } } [/size][/font][/backcolor][/color] 2107浏览量 1回复量 关注量 -
STC89C52单片机串口通信问题,求解答
使用的是STC89C52单片机,从另一个芯片上通过串口忘单片机上传数据,在串口调试助手上能看到传到单片机的数据,但是程序没有反应,求问大佬们为什么,多谢啦 #include
void UsartConfiguration(); unsigned char num = 'A'; sbit LED2=P2^0; void delay(unsigned int i) //延时函数 { unsigned int k; for (k=0;k 1789浏览量 4回复量 关注量