Sie sind auf Seite 1von 7

7seg_c.

c
#include <reg51.h> void MSDelay(unsigned int); void main(void) { while (1) //repeat forever { P0=0x80; MSDelay(250); P2=0xF9; MSDelay(250); P2=0x24; MSDelay(250); P2=0x30; MSDelay(250); } } void MSDelay(unsigned int itime) { unsigned int i,j; for (i=0;i<itime;i++) for (j=0;j<1275;j++); }

LCD.c
#include<reg51.h> #define cmdport P3 #define dataport P2 #define q 100 sbit rs = cmdport^0; //register select pin sbit rw = cmdport^1; // read write pin sbit e = cmdport^2; //enable pin

void delay(unsigned int msec) // Function to provide time delay in msec. { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); }

void lcdcmd(unsigned char item) //Function to send command to LCD { dataport = item; rs= 0; rw=0; e=1; delay(1); e=0; }

void lcddata(unsigned char item) //Function to send data to LCD { dataport = item; rs= 1; rw=0; e=1; delay(1); e=0; }

void main() { lcdcmd(0x38); // for using 8-bit 2 row mode of LCD delay(100); lcdcmd(0x0E); // turn display ON for cursor blinking delay(100); lcdcmd(0x01); //clear screen delay(100); lcdcmd(0x06); //display ON delay(100); lcdcmd(0x86); // bring cursor to position 6 of line 1 delay(100); lcddata('M'); delay(100);

lcddata('U'); delay(100); lcddata('N'); delay(100); lcddata('A'); delay(100); lcddata('Z'); delay(100); lcddata('A'); delay(100); return; }

LCD_Assembly.asm
;calls a time delay before sending next data/command ;P1.0-P1.7 are connected to LCD data pins D0-D7 ;P2.0 is connected to RS pin of LCD ;P2.1 is connected to R/W pin of LCD ;P2.2 is connected to E pin of LCD ORG 00h MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX ACALL COMNWRT ;call command subroutine ACALL DELAY ;give LCD some time MOV A,#0EH ;display on, cursor on ACALL COMNWRT ;call command subroutine ACALL DELAY ;give LCD some time

MOV A,#01 ;clear LCD ACALL COMNWRT ;call command subroutine ACALL DELAY ;give LCD some time MOV A,#06H ;shift cursor right ACALL COMNWRT ;call command subroutine ACALL DELAY ;give LCD some time MOV A,#84H ;cursor at line 1, pos. 4 ACALL COMNWRT ;call command subroutine ACALL DELAY ;give LCD some time MOV A,#'N' ;display letter N ACALL DATAWRT ;call display subroutine ACALL DELAY ;give LCD some time MOV A,#'O' ;display letter O ACALL DATAWRT ;call display subroutine AGAIN: SJMP AGAIN ;stay here COMNWRT: ;send command to LCD MOV P1,A ;copy reg A to port 1 CLR P2.0 ;RS=0 for command CLR P2.1 ;R/W=0 for write SETB P2.2 ;E=1 for high pulse CLR P2.2 ;E=0 for H-to-L pulse RET DATAWRT: ;write data to LCD MOV P1,A ;copy reg A to port 1

CLR P2.0 ;RS=0 for command CLR P2.1 ;R/W=0 for write SETB P2.2 ;E=1 for high pulse CLR P2.2 ;E=0 for H-to-L pulse RET DELAY: MOV R3,#50 ;50 or higher for fast CPUs HERE2: MOV R4,#255 ;R4 = 255 HERE: DJNZ R4,HERE ;stay until R4 becomes 0 DJNZ R3,HERE2 RET END

readPIN_C.c
//C program to get the status of bit P1.0, save it, and #include <reg51.h> sbit inbit=P1^0; sbit outbit=P2^7; bit membit; //use bit to declare //bit- addressable memory void main(void) { while (1) { membit=inbit; //get a bit from P1.0 outbit=membit; //send it to P2.7 send it to P2.7 continuously.

} } toggle.c #include <reg51.h> void MSDelay(unsigned int); void main(void) { while (1) //repeat forever { P2=0x55; MSDelay(250); P2=0xAA; MSDelay(250); } } void MSDelay(unsigned int itime) { unsigned int i,j; for (i=0;i<itime;i++) for (j=0;j<1275;j++); }

Das könnte Ihnen auch gefallen