ON 20020302@7:16:11 PM at page: http://www.piclist.com/techref/microchip/language/c/io/lcd/hitachilcd-cl/lcd_c.htm CDB-optusnet-AE5 Colin D Barnard added 'Code: //**Project Name: VFD //**File Name : vfd0_3.c //**Version : 0.3 //**Date : 24/02/2002 //**Revision : 28/02/2002 added bit swap routine //** : 02/03/2002 fixed error in display routine and added delay to //** : WR_PIN strobe. //** : //** //**Processor :16F84/628 //** //** Copyright CDB. email bodgy1@optusnet.com.au // Program to display data on a Futoba M202SD08GL vacuum fluorescent display. // Using parallel mode. Data is on port B and control on port A. // Connections as follows // // Display Pins. 1 3 5 7 9 11 13 15 // Data Bits. 7 6 5 4 3 2 1 0 // // Control Pins. 20 18 17 16 8 // Signal Name. Busy SEL WR TEST RST // // Pins 2 4 6 +5v; 10 12 14 Gnd // Pic Pins B7 B6 B5 B4 B3 B2 B1 B0 // D0 D1 D2 D3 D4 D5 D6 D7 // // PortA A0 A1 A2 A3 A4 // WR SEL TEST RST BUSY // A0-A3 output A4 input. // // WR, SEL active low. data latched on WR 0->1; RST must be momentarily grounded // at start up to activate display. #define F628 #ifdef F628 #include #else #include #endif #include "uS_delay.c" #define CONTROL_PORT PORTA #define DATA_PORT PORTB #define WR_PIN PA.B0 #define SEL_PIN PA.B1 #define TEST_PIN PA.B2 #define RST_PIN PA.B3 #define BUSY_PIN PA.B4 #define HIGH 1 #define LOW 0 #define STROBE (PORTA^=1) #define MAX_ROW 20 #define LINES 2 // VFD Control Commands #define LF 0x0A //Line Feed #define CR 0x0D //Carriage Return #define CUROFF 0x14 //DC4 #define CURON 0x13 //DC3 #define DIMM 0x04 //Dimming uses vfd_command #define DIM2 0x20 //Dimm 20% #define DIM4 0x40 //Dimm 40% #define DIM8 0x80 //Dimm 80% #define DIMF 0xFF //Dimm 100% #define VTS 0x12 //DC2 Mode #define NORM 0x11 //DC1 Mode #define HTS 0x09 //Tab right one space #define BSP 0x09 //Backspace #define DP 0x10 //Display position uses vfd_command #define RST 0x1F //Soft reset #ifdef F628 # __config 0x3F61 //16F628 fuse #else # __config 0x3FF1 //16F84(a) fuse #endif //Prototypes void main(); void setup(); void reset_vfd(); void test_vfd(); void vfd_display(unsigned char *disp_string); void vfd_out(unsigned char *text); void vfd_ch(unsigned char ch); void vfd_command(unsigned char com, unsigned char action); void vfd_position(unsigned char line,unsigned char pos); void main() { setup(); big_delay(10); //settling time reset_vfd(); //Hard reset test_vfd(); //Run inbuilt test routine SEL_PIN=LOW; //Enable display for data big_delay(10); vfd_ch(CUROFF); vfd_display("Futoba VFD Display"); big_delay(3000); vfd_command(LF,CR); vfd_display("Dimming 20%"); vfd_command(DIMM,DIM2); //20% brightness big_delay(5000); vfd_command(DIMM,DIMF); //Full brightness vfd_ch(RST); // Clear display vfd_ch(CUROFF); vfd_command(CR,LF); vfd_display("pos"); vfd_position(2,5); vfd_display("2,5"); big_delay(5000); vfd_ch(VTS); vfd_display(" vertical tab"); big_delay(5000); vfd_ch(RST); vfd_ch(CUROFF); vfd_display("Futoba VFD Display"); vfd_position(2,5); vfd_display("End of Demo"); vfd_command(DIMM,DIM4); //40% brightness while(1) { } //forever! } // cmcon=(1< D0 D1 D2 D3 D4 D5 D6 D7 // // Using the extra variable 'original1' saves 3 program words unsigned char buffer,original; void vfd_out(unsigned char *text) { const unsigned char table[16]= {0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07,0x0F}; unsigned char original1; original=*text; original1=original & 0x0f; // Mask off lower nibble buffer=table[original1]; //look up conversion pattern lower nibble #asmline swapf buffer,f ;swap places make it high nibble #asmline swapf original,f ;swap original byte around original&=0x0f; buffer|=table[original]; //look up pattern for new lower nibble //IOR with current contents DATA_PORT=buffer; //Bung it on to PORTB while (BUSY_PIN) { } STROBE; //Clock the data into the VFD small_delay(30); //100 microseconds STROBE; //Return pin low } void vfd_ch(unsigned char ch) { unsigned char *text; text=&ch; vfd_out(text); } void vfd_command(unsigned char com, unsigned char action) { vfd_ch(com); vfd_ch(action); } void vfd_position(unsigned char line,unsigned char pos) { if (line==LINES) { pos+=(MAX_ROW-1); } else { pos=-1; } vfd_command(DP,pos); } '553 Null recipient not accepted ON 20020304@8:38:44 PM at page: http://www.piclist.com/techref/microchip/language/c/io/lcd/hitachilcd-cl/lcd_c.htm JMN-EFP-786 James Newton edited the page