//Routine output data to LCD in 4 bit mode. // //with the choice of assigning the data bits to the top nibble or bottom //nibble of the data port. //Rs and Enable can be on seperate ports. /WR is not used and should be //hardwired to Ov. // // // // // // port for enable and rs may be changed by appropriate port declaration // //**copyright C D Barnard 7/10/2002 Version 1.0 // // #include #include //These must be included because of the #ifdef declarations #asmfunc lcd_num(conv,digit) #asmfunc num2hex(decimal) #asmfunc lcd_hex(dec) #asmfunc lcd_st(*string) //**************************************************************** unsigned char rs_state; void lcd_packet(unsigned char raw_data,unsigned char rs_state) { #ifdef TOP LCDPORT&=0x0F; //Clear top bits lcd_out(raw_data&0xF0,rs_state); //Send high nibble lcd_out(raw_data<<4,rs_state); //Swap byte and send low nibble Wait(10); //delay between data bytes #else LCDPORT&=0xF0; //Clear bottom bits lcd_out(raw_data&0x0F,rs_state); lcd_out(raw_data>>4,rs_state); Wait(10); #endif } void lcd_out(unsigned char lcd_data,unsigned char inst) { unsigned char bitmask; bitmask=1<0x94 and 0xD0->0xD4 for 4*20 display const unsigned char row[4]={0x80,0xC0,0x90,0xD0}; rs_state=0; //command mode line-=1; //adjust for human maths lcd_packet((row[line] + column),rs_state); //row + column required rs_state=1; Wait(1); } #endif #ifdef _lcd_st void lcd_st(unsigned char *string) { rs_state=1; //data mode while(*string) //while not end of string { lcd_packet(*string,rs_state); ++string; //move to next character } } #endif #ifdef _lcd_hex void lcd_hex(unsigned char dec) { unsigned char hexnum; rs_state=1; //data mode hexnum=num2hex(dec>>4); //convert decimal number lcd_packet(hexnum,rs_state); // pump it out hexnum=num2hex(dec&0x0F); lcd_packet(hexnum,rs_state); } #endif #ifdef _lcd_num //Converts decimal numbers to 9999 to ASCII void lcd_num(unsigned int conv, unsigned char digit,unsigned char lz) { unsigned int temp1,decnum; unsigned char hexnum; rs_state=1; //data mode if(digit==4) { decnum=conv/1000 ; //get the thousands hexnum=lzero(decnum,lz); //leading blank // hexnum=num2hex(decnum); //convert to ASCII hex lcd_packet(hexnum,rs_state); } if(digit>2) { //workout the remainder conv=conv%1000; decnum=conv/100; //get the hundreds hexnum=lzero(decnum,lz); // hexnum=num2hex(decnum); lcd_packet(hexnum,rs_state); } if(digit>1) { conv=conv%100; decnum=conv/10; //get the tens hexnum=lzero(decnum,lz); // hexnum=num2hex(decnum); lcd_packet(hexnum,rs_state); lz=0; } decnum=conv%10; hexnum=num2hex(decnum); //the units lcd_packet(hexnum,rs_state); } #endif #ifdef _num2hex unsigned char num2hex(unsigned char decimal) { unsigned char temp; if (decimal < 10) { temp= decimal+'0'; //if number less than 10 add 30h for ASCII No. } else { temp=decimal-10; //Number greater than ten add 41h temp+= 'A'; //to get number in hex } return (temp); } #endif #ifdef _lzero unsigned char lzero(unsigned char decimal, unsigned char showz) { if(decimal==0 && showz) return 0x20; else return num2hex(decimal); } #endif