![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hello people, I'm trying to get a PIC 16f84A to output it's PORT A to a PowerTip PC1602-ARS-F-EB Alphanumeric Display. I've got the code to do this with PORT B but would rather use PORT A with 5 wires. This will involve using the LCD in four wire mode. Can someone please tell me how to do this? ---------------------------------------------------------- /* connects 2 line LCD panel */ /* using Hitachi 44780 controller */ /* assigments as follows: */ /* PORTB:0 -----> LCD bit 4 */ /* PORTB:1 -----> LCD bit 5 */ /* PORTB:2 -----> LCD bit 6 */ /* PORTB:3 -----> LCD bit 7 */ /* PORTB:4 -----> LCD RS */ /* PORTB:5 -----> LCD E */ /* function prototypes */ char lcd_start ( void ) ; char lcd_clear ( void ) ; char lcd_print_ch ( char ch ) ; char lcd_print ( const char * message ) ; char lcd_cursor ( char x, char y ) ; /* You will have to change these bits */ /* if the hardware changes */ /* You will also need to change: */ /* setup_lcd and lcd_raw_send */ /* masks for control bits */ #define RSMASK 0x10 #define EBIT 0x05 /* defined values for delays */ /* tested up to 20Mhz PIC */ /* standard write delay */ #define PUTCH_DELAY 250 /* clear and cursor home take longer */ /* special delay for them */ #define CLEAR_DELAY 5000 /* power up delay to let the LCD settle */ #define POWER_UP_DELAY 10000 /* bit delay to let the ports settle */ #define BIT_DELAY 2 void lcd_delay ( int size ) { int i ; for ( i = 0 ; i < size ; i++ ) ; } /* sends a byte out to the LCD */ /* the byte is given by in, the */ /* mask is used to allow the */ /* state of RS to be set as well */ void lcd_raw_send ( unsigned char in, unsigned char mask ) { unsigned char pb ; /* use a PIC assembler */ /* to swap the nibbles in the */ /* input */ /* puts high nibble at the */ /* bottom of the byte */ asm swapf param00_lcd_raw_send,F /* OR in the mask */ pb = (in & 0x0f ) | mask ; /* OR in the other bits */ /* PORTB */ pb = pb | (PORTB & 0xc0) ; /* send the data */ /* send the data */ /* don't disturb the other */ /* bits in PORTB */ PORTB = pb ; /* let the bits settle */ lcd_delay ( BIT_DELAY ) ; /* now clock the bit out */ /* by raising and lowering E */ set_bit ( PORTB, EBIT ) ; /* let the bits settle */ lcd_delay ( BIT_DELAY ) ; clear_bit ( PORTB, EBIT ) ; /* put the low nibble back */ /* into in */ asm swapf param00_lcd_raw_send,F /* OR in the mask */ pb = (in & 0x0f ) | mask ; /* OR in the other bits */ /* PORTB */ pb = pb | (PORTB & 0xc0) ; /* send the data */ /* send the data */ /* don't disturb the other */ /* bits in PORTB */ PORTB = pb ; /* let the bits settle */ lcd_delay ( BIT_DELAY ) ; /* now clock the bit out */ /* by raising and lowering E */ set_bit ( PORTB, EBIT ) ; /* let the bits settle */ lcd_delay ( BIT_DELAY ) ; clear_bit ( PORTB, EBIT ) ; /* do the delay here */ lcd_delay (PUTCH_DELAY) ; } /* puts a character at the cursor */ /* position */ char lcd_print_ch ( unsigned char in ) { /* use raw send with RS set */ lcd_raw_send ( in, RSMASK ) ; return 1 ; } /* sends a command to the LCD */ void lcd_command ( unsigned char in ) { lcd_raw_send ( in, 0 ) ; } /* clear the display */ /* and home the cursor */ char lcd_clear ( void ) { lcd_command ( 0x01 ) ; /* do extra delay here */ lcd_delay (CLEAR_DELAY) ; lcd_command ( 0x02 ) ; /* do extra delay here */ lcd_delay (CLEAR_DELAY) ; return 1 ; } /* position the cursor */ char lcd_cursor ( unsigned char x, unsigned char y ) { if ( y==0 ) { /* position for line 0 */ y=0x80 ; } else { /* position for line 1 */ y=0xc0 ; } lcd_command ( y+x ) ; return 1 ; } const unsigned char lcd_init [5] = { /* LCD initialise */ 0x33, /* Set for 4 bit operation */ 0x32, /* Set for 2 line LCD */ 0x2c, /* Select move after write */ 0x06, /* disp. on cursor off blink off */ 0x0c } ; char lcd_start (void) { unsigned char i, t ; /* Select the Register bank 1 */ set_bit ( STATUS, RP0 ) ; /* set bits of PORTB for output */ /* change for different hardware */ /* clear bottom five bits for LCD */ /* don't change any other bits */ TRISB = (TRISB & 0xc0) ; /* Select the Register bank 0 */ clear_bit( STATUS, RP0 ); /* give the LCD time to settle */ /* from power up */ lcd_delay ( POWER_UP_DELAY ) ; for ( i=0 ; i < 5 ; i++ ) { lcd_command ( lcd_init [i] ) ; } lcd_clear () ; return 1 ; } /* lcd_print accepts a pointer */ /* parameter which points at the */ /* string to be printed */ char lcd_print ( const unsigned char * mess ) { unsigned char i = 0 ; /* treat the pointer as an */ /* array and send bytes until */ /* we find an element with 0 */ /* in it */ while ( mess [i] != 0 ) { lcd_print_ch ( mess[i] ) ; i++ ; } return 1 ; } const unsigned char hello [6] = { 'h','e','l','l','o',0x00 } ; void main ( void ) { unsigned char x, y ; unsigned char i = 0 ; while (1) { lcd_start () ; lcd_cursor ( 5, 0 ) ; lcd_print ( hello ) ; lcd_cursor ( 0, 0 ) ; lcd_print_ch ( 'x' ) ; lcd_cursor ( 15, 0 ) ; lcd_print_ch ( 'x' ) ; lcd_cursor ( 0, 1 ) ; lcd_print_ch ( 'x' ) ; lcd_cursor ( 15, 1 ) ; lcd_print_ch ( 'x' ) ; } while (1) ; } | |
| |
| | (permalink) |
| Anybody? I'm quite new to PIC programming. | |
| |