Discussion in "8051 Discussion Forum" started by    xx1mar    Dec 15, 2007.
Sat Dec 15 2007, 10:44 pm
#1
hello,

im newbie in c programming, kindly help me with this program.. Im using a DS89c450 microcontroller and three 7-seven segment display with port 1, 2 and port 3 as my output.. im making a text message using a 7-segment.. this program was too long and i want to add some more characters.. what is the syntax to shorten this program.. Thank you

this is my program
#include <stdio.h>
  //

#include <stdlib.h>
  //

#include <ds89c4xx.h>
  //


int d, d2;

/*
0 = a
1 = b
2 = c
3 = d
4 = e
5 = f
6 = g
*/

/*-------------------------------------
start delay program
-------------------------------------*/
void delay(void);
{
for (d=0; d<1000; d++)//delay
{
for (d2=0; d2<1000; d2++)//delay
{
;
}
}
}
/*-------------------------------------
end delay program
-------------------------------------*/


main()
{
while(1)
{
//H
P2 = 0x00;
P3 = 0x00;
P1 = 0x76;
delay();

//E
P2 = 0x00;
P3 = 0x76;
P1 = 0x79;
delay();

//L
P2 = 0x76;
P3 = 0x79;
P1 = 0x38;
delay();

//L
P2 = 0x79;
P3 = 0x38;
P1 = 0x38;
delay();

//O
P2 = 0x38;
P3 = 0x38;
P1 = 0x3F;
delay();


}
}


[ Edited Sat Dec 15 2007, 10:53 pm ]
Sat Dec 15 2007, 10:58 pm
#2
you want to shorten just the length of program or the code size?
Sat Dec 15 2007, 11:12 pm
#3
Thanks ajay for the reply, i want to shorten the code size because i want to display at least 100 characters.. is it possible sir?
Sun Dec 16 2007, 12:13 am
#4
well yes you can do it.. use for loop and define an array to send values one by one..
something like this...

unsigned char disp[9] = {0x00, 0x00, 0x76, 0x79, 0x38, 0x38, 0x3F, 0x00, 0x00};
unsigned char i;
while(1){
	for (i=0;i<7;i++){
		P2 = disp[i];
		P3 = disp[i+1];
		P1 = disp[i+2];
		delay();
	}
}
Sun Dec 16 2007, 01:03 am
#5
im sorry sir, but i cant get the loop.. im using keil program and theres an error

this is the code

#include <stdio.h>
   //
#include <stdlib.h>
    //
#include <ds89c4xx.h>
   //

int d, d1;
unsigned char i;
unsigned char disp[9] = {0x00, 0x00, 0x76, 0x79, 0x38, 0x38, 0x3F, 0x00, 0x00};

delay()
{
	for (d=0; d<1500; d++)//delay
	{
		for (d2=0; d2<1500; d2++)//delay
		{
		;
		} 
	} 
}
main()

	while(1)
	{
	   for (i=0;i<7;i++){
                P2 = disp[i];
                P3 = disp[i+1];
                P1 = disp[i+2];
                delay();

	}		
}	 																    		
)



[ Edited Sun Dec 16 2007, 05:30 pm ]
Sun Dec 16 2007, 10:39 am
#6
there surely is an error....

main()

while(1)
{


braces mising after main()
main()
{
while(1)
{


and the extra ')' in the end...
plz.. check..

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am