请给一个飞思卡尔单片机控制1602显示器的最简单的程序
发布网友
发布时间:2022-05-12 19:08
我来回答
共4个回答
热心网友
时间:2023-10-19 01:42
ORG 0000H
LJMP START
ORG 0100H
START:MOV A,#30H R:10K~20KR3.VEEP1.3P1.2P1.1P1.0P3.0P3.3P3.19.DB210.DB3CML5.R/W7.DB08.DB16.E4.RSMPU2.VCC(+5V)1.VSS(0V)2.VDD1.VSS
LCALL OUTI
LCALL MS4MS
MOV A,#30H
LCALL OUTI
LCALL MS100US
MOV A,#30H
LCALL OUTI
LCALL BUSY
MOV A,#20H
LCALL OUTI
MOV A,#28H ;FUNC:DL=1 FOR BITS,N=1 FOR 2 LINES
LCALL OUTI
MOV A,#01H ;CLEAR SCREEN
LCALL OUTI
MOV A,#08H
LCALL OUTI
MOV A,#0CH ;ON DISPLAY
lcall outi
MOV A,#06H ;AC INCREMENT
LCALL OUTI
MOV A,#80H ;DDRAM ADDRESS
LCALL OUTI
MOV R1,50H
TTR1:MOV A,#0FEH ;DISPLAY "SPACE"
LCALL OUTD
DJNZ R1,TTR1
MOV A,#02H ;DISPLAY RETURN
LCALL OUTI
LCALL MS40
LCALL MS40
lcall ms40
MOV R1,#50H
TTR2:MOV A, #0FFH ;DISPLAY "BLACK"
LCALL OUTD
DJNZ R1,TTR2
MOV A,#02H
LCALL OUTI
LCALL MS40
LCALL MS40
lcall ms40
MOV A,#80H
MOV R3,A
LCALL OUTI
MOV R1,#28H
MOV A,#61H
MOV R7,A
TTR4:LCALL OUTD
INC R3
MOV A,R3
LCALL OUTI
INC R7
MOV A,R7
DJNZ R1,TTR4
MOV A,#0C0H
MOV R3,A
LCALL OUTI
MOV R1,#28H
MOV A,#30H
MOV R7,A
TTR5:LCALL OUTD
INC R3
MOV A,R3
LCALL OUTI
INC R7
MOV A,R7
DJNZ R1,TTR5
LCALL MS40
LCALL MS40
LCALL MS40
LJMP START
MS4MS:MOV R5,#08H
MS1: MOV R4,#0FFH
MS2: DJNZ R4,MS2
DJNZ R5,MS1
RET
MS100US:MOV R5,#12H
MS3: MOV R4,#1FH
MS4: DJNZ R4,MS4
DJNZ R5,MS3
RET
BUSY:SETB P3.1
SETB P3.1
CLR P3.3
CLR P3.3
TT00:SETB P3.0
SETB P3.0
MOV A,P1
CLR P3.0
CLR P3.0
ANL A,#80H
JNZ TT00
RET
CHANGE:MOV 13H,A
SWAP A
MOV 12H,A
ANL 13H,#0F0H ;HIGH 4 BITS
ANL 12H,#0F0H ;LOW 4 BITS
RET
;OUT INSRCTION
OUTI:LCALL CHANGE
LCALL BUSY
CLR P3.1
CLR P3.1
CLR P3.3
CLR P3.3
SETB P3.0
SETB P3.0
MOV A,13H
MOV P1,A
CLR P3.0
CLR P3.0
ANL P1,#07H
SETB P3.0
SETB P3.0
MOV A,12H
MOV P1,A
CLR P3.0
CLR P3.0
MOV R4,#02H ;DELAY 1MS
TM4: MOV R5,#0FFH
TM5: DJNZ R5,TM5
DJNZ R4,TM4
RET
;OUT DATA
OUTD:LCALL CHANGE
LCALL BUSY
CLR P3.1
CLR P3.1
SETB P3.3
SETB P3.3
SETB P3.0
SETB P3.0
MOV A,13H
MOV P1,A
CLR P3.0
CLR P3.0
ANL P1,#00
SETB P3.0
SETB P3.0
MOV A,12H
MOV P1,A
CLR P3.0
CLR P3.0
MOV R4,#0FFH ;DELAY 0.5MS
TM2: DJNZ R4,TM2
RET
MS40:MOV R4,#0FFH ;DELAY ABOUT 132MS
MS5: MOV R5,#0FFH
MS6: DJNZ R5,MS6
DJNZ R4,MS5
RET
热心网友
时间:2023-10-19 01:43
你用CodeWarrior5.0新建一个工程,把我下面的程序拷贝到你的MAIN.C全部覆盖后,改一下端口就行了,还不会的话我传个你
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#define LCD_DATA PORTA
#define LCD_RS PTS_PTS6 //PS6
#define LCD_RW PTS_PTS7 //PS7
#define LCD_E PORTK_BIT7 //Pk7
void LCD_Delay(word x) //x取值1~255;
{
int ii,jj;
for(ii=0;ii<x;ii++)
for(jj=0;jj<5;jj++); //16MHz--1us
}
void delay_ms(int ms) //x取值1~255;
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<2770;jj++); //32MHz--1ms
//for(jj=0;jj<4006;jj++); //48MHz--1ms
//for(jj=0;jj<5341;jj++); //64MHz--1ms
}
//-----------------------------------------------------
void setbusclock(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=1;
REFDV=1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
_asm(nop); //BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void LCD_Write_Data(uchar dat)
{
LCD_DATA=dat;
LCD_RS=1;
LCD_RW=0;
LCD_E=0;
LCD_Delay(5);
LCD_E=1;
LCD_Delay(5);
LCD_E=0;
LCD_Delay(5);
}
void LCD_Write_Cmd(uchar cmd)
{
LCD_DATA=cmd;
LCD_RS=0;
LCD_RW=0;
LCD_E=0;
LCD_Delay(5);
LCD_E=1;
LCD_Delay(5);
LCD_E=0;
LCD_Delay(5);
}
void LCD_Disp_Char(uchar X,uchar Y,uchar DData)
{
Y &=0x01;
X &=0x0F;
if(Y) X|=0x40;
X|=0x80;
LCD_Write_Cmd(X);
LCD_Write_Data(DData);
}
void LCD_Disp_String(uchar X,uchar Y,uchar *DData)
{
uchar StringLength;
StringLength=0;
Y &=0x01;
X &=0x0F;
while(DData[StringLength]!='\0')
{
if(X<=0x0F)
{
LCD_Disp_Char(X,Y,DData[StringLength]);
StringLength++;
X++;
}
}
}
void LCD_Init(void)
{
LCD_Write_Cmd(0x38);
delay_ms(30);
LCD_Write_Cmd(0x0e);
delay_ms(30);
LCD_Write_Cmd(0x06);
delay_ms(30);
LCD_Write_Cmd(0x01);
delay_ms(30);
LCD_Write_Cmd(0x81);
delay_ms(30);
}
void main(void){
DDRS=0xff;
DDRK=0xff;
DDRA=0xff;
setbusclock();
EnableInterrupts;
LCD_Init();
LCD_Disp_String(0,0,"happy new year") ;
while(1)
{
}
}
你发个邮箱 我给你发去
热心网友
时间:2023-10-19 01:43
8月30日,标记。
如果一星期内没人回答你,我再发程序。
简单配置一下IO和时钟,下个51的1602的C语言程序就能跑,总共没几行,至于连文件夹(你是指完整的工程文件吧)都要吗?
1602太常见了,好的驱动程序都差不多,楼上写的就挺好的。尤其是字符显示程序,我和你一样都用的指针,而且你比我的多了一个Y值,挺适合不熟悉1602的人用的。
热心网友
时间:2023-10-19 01:44
工程文件我给你发过去了 谁要是要的话问楼主要 或者问我要吧