CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help me...!! it so close to complete....but i can't solve it

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fazreen



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

help me...!! it so close to complete....but i can't solve it
PostPosted: Fri Nov 23, 2012 2:07 am     Reply with quote

aim :
-when push button1, the data 'a' will transmit and receive and the led will lighting,lcd will display switch on bed1 .

- when push button 2,the data 'b' will transmit and receive and led will lighting, lcd will display switch on bed2.

-if button 1 and 2 are not switch on...it will receive data 'c' that led will switch off and lcd will display switch off bed.

problem :

- they not receive the data...
-sometime data 'a' and 'b' receive but data 'c' not reiceve...
-overall,this program are very close to complete but i can solve complete it because of have a small problem that i can't solve.

( only use 2 button, lcd , and only one led )





#include <18F4550.h> // PIC18F4550 HEADER FILE

#fuses PUT, HS, NOWDT, NOLVP, NOBROWNOUT, // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING

#use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors ) // 4 MHZ CRYSTAL
#include <lcd.c>


#define LED1 PIN_B6 // LED 1
//#define LED2 PIN_B7 // LED 2

#define BUTTON1 PIN_B0 // button1
#define BUTTON2 PIN_B1 // BUTTON2

#define LCD_E PIN_D0 // PIN E
#define LCD_RS PIN_D1 // PIN RS
#define LCD_RW PIN_D2 // PIN RW
#define LCD_D4 PIN_D4 // PIN D4
#define LCD_D5 PIN_D5 // PIN D5
#define LCD_D6 PIN_D6 // PIN D6
#define LCD_D7 PIN_D7 // PIN D7

void main ()
{
char data;
set_tris_b(0x01); // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT
//set_tris_d(0xFF);
//set_tris_c(0x80); // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000)

output_b(0x00);
output_d(0xff);

lcd_init();

while(true)
{

while(!input(BUTTON1))
{

putc('a');


while(!input(BUTTON2))
{

putc('b');


while((input(BUTTON1))||(input(BUTTON2)))
{

putc('c');


data = getc();
switch(data)
{

case 'a' :output_high(PIN_B6);
printf(lcd_putc,"\fSWITCH ON BED1");
delay_ms (300);
break;

case 'b' :output_high(PIN_B6);
printf(lcd_putc,"\fSWITCH ON BED2");
delay_ms (300);
break;

case 'c' :output_low(PIN_B6);
printf(lcd_putc,"\fSWITCH OFF BED");
delay_ms (300);
break;

break;
}
}


}
}
}
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 2:18 am     Reply with quote

1) Learn to use the code buttons.
2) Do you have a 20MHz crystal, or 4MHz. Serial won't work, till your clock setup is right. Currently you have the HS oscillator (which says greater than 4MHz clock), 20MHz selected (which says I am using a 20MHz crystal), yet comment '4MHz crystal'.....
3) LCD pin defines need to be _before_ lcd.c is loaded.
4) Your comments disagree almost everywhere with what you do. For instance:
Code:

set_tris_b(0x01); // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT

This has b0 as input, and B1 to 7 as output. Not what the comment says....
Then:
Code:

output_b(0x00);

You have now set the whole of port B as output.....
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 4:18 am     Reply with quote

Quote:
-sometime data 'a' and 'b' receive but data 'c' not reiceve...
-overall,this program are very close to complete but i can solve complete it because of have a small problem that i can't solve.
No. You're nowhere near complete.

You use the word "sometime" to describe what's going on. That's usually bad news.

How do you know what's happening?
How can you tell what's being transmitted?
How do you know what's being received?
How are your buttons wired?
Have you got pull up resistors on your buttons?

Mike
fazreen



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 4:30 am     Reply with quote

Mike Walne wrote:
Quote:
-sometime data 'a' and 'b' receive but data 'c' not reiceve...
-overall,this program are very close to complete but i can solve complete it because of have a small problem that i can't solve.
No. You're nowhere near complete.

You use the word "sometime" to describe what's going on. That's usually bad news.

How do you know what's happening?
How can you tell what's being transmitted?
How do you know what's being received?
How are your buttons wired?
Have you got pull up resistors on your buttons?

Mike


dear mike...

I test this program by using proteus software... i had build 2 pic for communicate.. and only one pic has lcd, button and led. I had test program in proteus... if it complete...i will transfer this program into real pic...

1. What i want is, when i push button 1, it will request for data 'a' and receive it. When i push button 2...it will request for data 'b' n receive it. When both button are switch off.... the data 'c' will receive.
fazreen



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 4:41 am     Reply with quote

Quote:
You have now set the whole of port B as output.....



okay...i'll try again later...
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 5:02 am     Reply with quote

This is all very much like the thread you ran a month ago.

After several posts, you suddenly declared it was all OK.

Now it's not, AND you just got round to telling us it's Proteus.

I'm out, 'til you get some results with REAL hardware.

Mike

PS You only NEED to build ONE board. Use a PC to communicate with it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group