Name: | Mr. Colin D Barnard |
Company: | |
Web Site: | |
Code Pages:
Code:
These file were compiled by the Wiz C compiler from FORED. www.fored.co.uk lcd_shiftout.h extern shiftport; extern clockport; extern latchport; void lcd_init(void); void out_74595(unsigned char shift_data); void lcd_out(unsigned char lcd_data,unsigned char rs_bit); void lcd_packet(unsigned char raw_data,unsigned char rs_bit); void lcd_clear(); void lcd_st(unsigned char *string); void lcd_num(unsigned int conv); void lcd_hex(unsigned char dec); void lcd_pos(unsigned char line,unsigned char column); unsigned char num2hex(unsigned char decimal); //extern unsigned char bit_no; //extern unsigned char rs_state; //extern unsigned char clockbit,latchbit; lcd_shift. library file //Routine using 74HC595 to shift out data to LCD in 4 bit mode. //This only uses 3 pins from the PIC - Latch, Clock, Data. // Pin outs // 74_595 LCD //Q7 7 DB4 //Q6 6 DB5 //Q5 5 DB6 //Q4 4 DB7 //Q2 3 RS //Q1 2 EN // // port for clock and latch may be changed by appropriate port declaration // //**copyright C D Barnard 1/5/2002 Version 1.2 //#include#include "lcd_shiftout.h" #include //These must be included because of the #ifdef declarations #asmfunc lcd_num(conv) #asmfunc num2hex(decimal) #asmfunc lcd_hex(dec) #asmfunc lcd_st(*string) //**************************************************************** // 74HC595 to LCD routines void lcd_packet(unsigned char raw_data,unsigned char rs_state) { lcd_out(raw_data>>4,rs_state); lcd_out(raw_data&0x0F,rs_state); Wait(10); //delay between data bytes } void lcd_out(unsigned char lcd_data,unsigned char inst) { inst<<=4; //shift RS state to bit 4 of data stream out_74595(lcd_data|inst); //enable=0 out_74595(lcd_data|(0x20 | inst)); //enable=1 out_74595(lcd_data|inst); //enable=0 } //This could be replaced with pClockOut(8,lcd_data|inst) etc void out_74595(unsigned char shift_data) { unsigned char bitcount,bitmask; bitmask=1< >=1; //Next data bit } latchport^=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 int temp1,decnum; unsigned char hexnum,suppress=0; rs_state=1; //data mode decnum=conv/1000 ; //get the thousands if (decnum==0) { //if none then suppress leading zero hexnum=0x20; //possibly change SPACE's to 0x00 NULL's suppress=1; } else { hexnum=num2hex(decnum); //convert to ASCII hex } lcd_packet(hexnum,rs_state); temp1=conv-(decnum*1000); //workout the remainder decnum=temp1/100; //get the hundreds if (decnum ==0 && suppress) hexnum=0x20; else { hexnum=num2hex(decnum); suppress=0; } lcd_packet(hexnum,rs_state); temp1=temp1-(decnum*100); decnum=temp1/10; //get the tens if (decnum < 1 && suppress) hexnum=0x20; else hexnum=num2hex(decnum); lcd_packet(hexnum,rs_state); decnum=temp1-(decnum*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 Demo.c putting it all together #define shiftport PORTB #define clockport PORTB #define latchport PORTB const char bit_no=7; unsigned char rs_state; const char clockbit=5; const char latchbit=6; #include #include "lcd_shiftout_1.c" //config info only included whilst testing # __config 0x3F61 void main(void) { PORTA=PORTB=0; TRISA=TRISB=0; lcd_init(); lcd_packet('V',1); lcd_hex(2); lcd_packet('.',1); lcd_hex(19); lcd_st("Shift Demo"); Wait(6000); lcd_clear(); //Wait(2000); lcd_pos(1,3); lcd_st("74HC595 End"); lcd_pos(2,6); lcd_num(1024); while(1); }
Comments Pages:
Questions:
I tried to understand the code by C Barnard abour LCD with 74HC595. Looks like there are missing lines or statements, unless I missed something. i.e.: in out74595, "shift_data" is never used, as well as "bitcount" "bitmask". LCD_init is missing (unless you wrote it elsewhere, and anyway it is easy to write). Furthermore, I'm not really C expert (!!) and compact C writing is somewhat difficult to understand!! "bitmask=1<>=1" for instance is more than a labyrinth to mee!! Thanks for all, and anyway great job on this site. Gerard, F6EEQ+
file: /Techref/member/CDB-optusnet-AE5/index.htm, 8KB, , updated: 2012/7/30 03:26, local time: 2024/11/5 00:37,
owner: CDB-optusnet-AE5,
3.14.142.131:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/Techref/member/CDB-optusnet-AE5/index.htm"> Member Homepage for CDB-optusnet-AE5</A> |
Did you find what you needed? |