Hello, I am writing a program (using SDCC) for the pic16f887, it is driving
a Hitachi HD44780 character LCD. In the code I am trying to write
characters to the LCD. First: directly 1 character at a time and then
Second: using what is essentially the puts function (void puts_lcd(char
*s)). The puts function fails to send anything more than the first
character. What am I doing wrong ? or is it a compiler error ? relevant
files are attached. Thanks ...

>void puts_lcd (char *s)
>{
>    REG_SEL=1;
>
>    while (*s)
>    {
>        lcd_command(*s++);
>    }
>
>    REG_SEL=0;
>}

-- 
Jason White
/** 16x2 Hitachi LCD Driver Program
 **
 ** Processor PIC16F887  @ 8 MHz
 ** SDCC Compiler 
 **
 ** Author Jason White
 ** Copyright (c) 2010 Jason White  <White Waters Software>
 ** whitewaterssoftwarei...@gmail.com
 **/

/* ----------------------------------------------------------------------- */
/* Definitions */

#include <pic16f887.h>
#include <stdlib.h>

/* ----------------------------------------------------------------------- */
/* Configuration */

typedef unsigned int word;
word at _CONFIG1 CONFIG1 = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_OFF & _FCMEN_OFF & _LVP_OFF & _DEBUG_OFF;
word at _CONFIG2 CONFIG2 = _BOR40V & _WRT_OFF;


/* ----------------------------------------------------------------------- */
/* Interrupt Routine */

void isr() interrupt 0 
{

}

/* ----------------------------------------------------------------------- */
/* Global Vars */

long i=0;
char j=0;

/* ----------------------------------------------------------------------- */
/* Function Pre-Definitions */

/* ----------------------------------------------------------------------- */
/* Main Code */

void wait(long time)
{
	for(i=0;i<time;i++)
	{
	__asm
		clrwdt
		; Delay = 0.0001 seconds
		; Clock frequency = 8 MHz
		
		; Actual delay = 0.0001 seconds = 200 cycles
		; Error = 0 %
		
			cblock
			d1
			endc
		
					;199 cycles
			movlw	0x42
			movwf	d1
			decfsz	d1, f
			goto	$-1
		
					;1 cycle
			nop


	__endasm;
	}
}

void wdt()
{
	__asm
		clrwdt
	__endasm;
}

#define CLOCK RC7
#define READ RD6
#define REG_SEL RD5

#define LED RD2

void lcd_command(char cmd)
{
	CLOCK=0;

	PORTB=cmd;//j;

	wait(100);//.01 seconds
	CLOCK=1;
	wait(100);//.01 seconds
	CLOCK=0;
}

void puts_lcd (char *s)
{
	REG_SEL=1;
	
	while (*s)
	{
		lcd_command(*s++);
	}
	
	REG_SEL=0;
}


void main()
{
	int counter=0;
	wdt();
	
	IRCF0=1;
	IRCF1=1;
	IRCF2=1;
	
	PORTA=0;
	PORTB=0;
	PORTC=0;
	PORTD=0;
	PORTE=0;
	
	TRISA=0x1F;
	TRISB=0;
	TRISC=0;
	TRISD=0;
	TRISE=0;
	
	ANSEL=0;
	ANSELH=0;

	LED=1;

	wait(1000);//.1 seconds

	LED=0;

	wait(1000);//.1 seconds

	lcd_command(0x38); //Function Set

	lcd_command(0x0F); //Display On

	lcd_command(0x06); //Entry Mode Set
	
	lcd_command(0x01); //Clear Display
	
	REG_SEL=1;

	lcd_command('F');
	lcd_command('o');
	lcd_command('o');
	lcd_command('b');
	lcd_command('a');
	lcd_command('r');
	lcd_command(' ');
	lcd_command('!');
	
	REG_SEL=0;
	
	puts_lcd("~Hello");

	while (1)
	{
		LED=1;
		wait(1000);//1 second
		LED=0;
		wait(1000);//1 second
	}
}

Attachment: 887-lcd-test.cod
Description: application/vnd.rim.cod

:020000040000FA
:1000000000008A110A121029F200030E8301F10088
:100010000A088A01F000040883120313B90084005F
:1000200070088A008301710E8300F20E720E0900BF
:10003000CC20831603130F168F160F17831203138A
:10004000850186018701880189011F30831603130A
:1000500085008601870188018901831603178801BD
:100060008901831203130815E830FD000330FE00F8
:100070000030FF000030CE20831203130811E83057
:10008000FD000330FE000030FF000030CE2038308D
:10009000B1200F30B1200630B1200130B1208312E1
:1000A000031388164630B1206F30B1206F30B12075
:1000B0006230B1206130B1207230B1202030B120E7
:1000C0002130B120831203138812013083120313ED
:1000D000B200EC30B1008030B3003108FE003208CD
:1000E000FF0033088B20831203130815E830FD004E
:1000F0000330FE000030FF000030CE2083120313D7
:100100000811E830FD000330FE000030FF00003031
:10011000CE207328080083120313AF007F08AE00BF
:100120007E08B0008312031388168312031330086D
:10013000FE002E08FF002F088A110A12A4218A113E
:100140000A1283120313AD002D080319AD28B00A5B
:100150000319AE0A2D08B1209528831203138812C3
:10016000080083120313860087136430FD000030FB
:10017000FE000030FF000030CE20831203138717EB
:100180006430FD000030FE000030FF000030CE2063
:1001900083120313871308006400080083120313FB
:1001A000AF007F08AE007E08AD007D08AC00831272
:1001B0000313B401B501B601B70183120313370865
:1001C000803E83120313B0002F08803E3002031DCF
:1001D000FD282E08831203133602031DFD28831207
:1001E00003132D08831203133502031DFD28831208
:1001F00003132C0883120313340203180F2964001D
:1002000042308000800B0229000083120313B40ADD
:100210000319B50A0319B60A0319B70ADD2808003D
:10022000D830FE000130FF0080308A110A12B72159
:100230008A110A1283120313A1007F08A000DA308A
:10024000A2000130A300831203132008A400210898
:10025000A500FF30A007031CA103240825040319EF
:10026000A02904302207A400A501A50D2308A50795
:100270002408FE002508FF0080308A110A12B721E9
:100280008A110A1283120313A7007F08A60022080E
:10029000FE002308FF0080308A110A12B7218A115C
:1002A0000A1283120313A900A5007F08A800A40066
:1002B00002302207A400A501A50D2308A5072408E4
:1002C000FE002508FF0080308A110A12B7218A112A
:1002D0000A1283120313A500AB007F08A400AA0032
:1002E000831203132608AA002708AB00FF30A607D5
:1002F000031CA7032A082B04031999292808FE00C8
:100300002908FF0080308A110A12A4218A110A12DA
:1003100083120313AA00240884008313251883176B
:100320002A088000A80A0319A90AA40A0319A50A21
:100330007029063083120313A2070318A30A232986
:100340008A110A1218280800003A0319AB29803ACA
:100350000319B22900347E08840083137F188317A1
:10036000000808007F088A007E0882000800003A22
:100370000319BF29803A0319C929FF0100347E08F7
:10038000840083137F1883170008FF00840A000885
:1003900008008A110A12B221FD00FE0FFF03FF0AB6
:1003A0008A110A12B221FC007D08FF007C080800B7
:1003B00003340034F334013434340034043400346E
:1003C000F73401343834003401340034F834013463
:1003D0003A340034013400347E34483465346C34AB
:1003E0006C346F3400340034003400340034003492
:0203F0000034D7
:02400E00D423B9
:02401000FF3F70
:00000001FF
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to