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

How to use enumeration in PIC

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







How to use enumeration in PIC
PostPosted: Sun Jun 03, 2007 10:59 pm     Reply with quote

Hi, i'm a newbies in PIC programming. I would like to know if anyone out there can help me to use enum...

Below is my codes..when I viewing the output from hyperterminal, the output is go to default value in switch-case.

Any idea??
Regards

#include <16f877a.h>
#include <string.h>

#use delay(clock=20000000)
#fuses XT,NOWDT,NOPROTECT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

enum jenis{
berhenti, masalah, keDepan, keKiri, keKanan
}statusDepan;

void main()
{
mulakan_sonic();
mulakan_psensor();

while(1){
monitor_distance_sensor1();
monitor_distance_sensor2();
read_ObjectSensors(dpnKiri,dpnKanan,blkgKiri,blkgKanan);
statusDepan = PeriksaHalanganDepan(dpnKiri,dpnKanan,jDepan);
switch(statusDepan)
{
case masalah:
printf("Terdapat masalah menentukan halangan di hadapan\r\n\n");
break;
case berhenti:
printf("Robot berhenti..\r\n\n");
break;
case keDepan:
printf("Robot bergerak ke hadapan..\r\n\n");
break;
case keKiri:
printf("Robot bergerak ke kiri..\r\n\n");
break;
case keKanan:
printf("Robot bergerak ke kanan..\r\n\n");
break;
default:
printf("Gagal menentukan aksi..%s\r\n\n",statusDepan);
break;
}

delay_ms(2000);
}
}

char PeriksaHalanganDepan(int8 dpnKiri,int8 dpnKanan, float jDepan)
{
char status[20];

if (jDepan>60)
{
if (dpnKiri<80 && dpnKanan<80>80 && dpnKanan>80)
strcpy(status,"berhenti");
else if(dpnKiri>80 || dpnKanan<80)
strcpy(status,"keKanan");
else if(dpnKiri<80>80)
strcpy(status,"keKiri");
else
strcpy(status,"masalah");
}
else
strcpy(status,"berhenti");
return status;
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jun 04, 2007 1:40 am     Reply with quote

First a general comment: Read the topic on top of this forum called 'Posting code in this Forum'. Here you will find some usefull information on how to post code to this forum. For example, using the 'code' buttons will help preserve the layout of your code which makes reading easier to us (and gets you more and quicker responses).

Second, always add the NOLVP fuse to your code. 99% of the programmers are of the high-voltage type. Without the NOLVP fuse your PIC might stall with a voltage spike on pin B3 (PGM).

For the enumeration problem: enums are integer values, not strings.
So instead of using a string copy you have to do something like
Code:
status = masalah;
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