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

basic pic code

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







basic pic code
PostPosted: Thu Apr 13, 2006 8:15 pm     Reply with quote

I'm writing basic pic code for a PIC16F88. All I want to do is for basic testing purposes just output a high for the digit for in (Pin_B0) by setting the user2 value to 1. For some reason, I cannot get this basic code to work, please help. Most of this code is commented out to test. All I want to do is the function settemp. When I compile and run this code, nothing lights up at all.

#include <16F88.h> // <-- This is the type of PIC you're using.
// Other supported PICs are in:
// C:\Program Files\PICC\Devices

//#device ICD=TRUE
#device *=16 ADC=10 // Use 16-bit pointers, use 10-bit ADC

#fuses HS // You may or may not want some of these ....
#fuses NOWDT
#fuses NOPROTECT
#fuses NOLVP
#fuses NODEBUG
#fuses NOPUT
#fuses NOBROWNOUT

#use delay(clock=20000000)
// These require use of Set_Tris_x()
#use fast_io(A)
#use fast_io(B)

// End Preprocessor Directives


#include "Include\Compiler.h"
#include "Include\Globals.h"



/******************************************************************************\
* *
* F U N C T I O N P R O T O T Y P E S *
* *
\******************************************************************************/
// when you test, comment out all ADC stuff, comment out calculate temp
//void initADC(void);
void settemp(int8 user2, int8 user1, int8 user0);
//void calculatetemp(int actual2, int actual1, int actual0, int16 adcvalue);
//void checkpushbutton(int8 user2, int8 user1, int8 user0, int1 check);
//void inctemp(int8 user2, int8 user1, int8 user0);
//void dectemp(int8 user2, int8 user1, int8 user0);
void setdigit1(int8 user2);
void setdigit2(int8 user1);
void setdigit3(int8 user0);
//void comparetemp(int8 user2, int8 user1, int8 user0, int8 actual2, int8 actual1, int8 actual0);


/******************************************************************************\
* *
* M A I N R O U T I N E *
\******************************************************************************/
#pragma zero_ram // Interesting command ....

int8 user2 = 1;
int8 user1 = 0;
int8 user0 = 0;
int8 actual2 = 0;
int8 actual1 = 9;
int8 actual0 = 9;
int1 check = true;
int16 adcvalue=0.0;

void main( void)
{
Backlight_Enabled = 0;

disable_interrupts(GLOBAL); // We don't want to be interrupted yet

output_low(Pin_A0);
output_low(Pin_A1);
output_low(Pin_A2);
output_low(Pin_A3);
output_low(Pin_A4);
output_low(Pin_A5);
output_low(Pin_A6);
output_low(Pin_A7);
output_low(Pin_B0);
output_low(Pin_B1);
output_low(Pin_B2);
output_low(Pin_B3);
output_low(Pin_B4);
output_low(Pin_B5);
output_low(Pin_B6);
output_low(Pin_B7);

delay_ms(50); // wait for voltages to stablize

Set_Tris_A(0b00111100); // Port A's I/O, 0b00010001
Set_Tris_B(0b00000000);
//output_low(Pin_B6); // should be output_low(Pin_B6)


settemp(user2, user1, user0);
//initADC();
/*
while(forever)
{
// calculatetemp(actual2, actual1, actual0, adcvalue);
checkpushbutton (user2, user1, user0, check);

if(check==true)
{
setdigit1(actual2);
setdigit2(actual1);
setdigit3(actual0);
}


else
{
setdigit1(user2);
setdigit2(user1);
setdigit3(user0);
}

comparetemp(user2, user1, user0, actual2, actual1, actual0);
}
*/
}

void settemp(int8 user2, int8 user1, int8 user0)
{
setdigit1(user2);
setdigit2(user1);
setdigit3(user0);
}

//setting up a to d converter
/*
void initADC(void)
{
setup_adc_ports(sAN2); // A0 A1 Ref=A2,A3
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel( 2 );
delay_us(10);
}
*/

/*
void calculatetemp(int actual2, int actual1, int actual0, int16 adcvalue)
{
float temp=0.0;
adcvalue = read_adc();
temp= (adcvalue/1023);
temp=temp*3.5;
temp=temp*63.28-9.48;
adcvalue=temp/1;

while(adcvalue > 99)
{
actual2 += 1;
adcvalue-= 100;
}
while(adcvalue > 9)
{
actual1 += 1;
adcvalue -= 10;
}
while(adcvalue > 0)
{
actual0 += 1;
adcvalue -= 1;
}

}
*/

/*
void checkpushbutton(int8 user2, int8 user1, int8 user0, int1 check)
{
if(input(Pin_A3)==1)
check=!check;

if(input(Pin_A4)==1)
inctemp(user2, user1, user0);

if(input(Pin_A5)==1)
dectemp(user2, user1, user0);
}
*/
/*
void inctemp(int8 user2, int8 user1, int8 user0)
{
if(user0==9)
{
user0=0;
if(user1==9)
{
user1=0;
user2++;
}
else user1++;
}
else user0++;
}
*/
/*
void dectemp(int8 user2, int8 user1, int8 user0)
{
if(user0==0)
{
user0=9;
if(user1==0)
{
user1=9;
user2--;
}
else user1--;
}
else user0--;
}
*/


// Display digit 1

void setdigit1(int8 user2)
{
if(user2==0)
{
output_low(Pin_B0);
output_low(Pin_B1);
}

if(user2==1)
{
output_high(Pin_B0);
output_low(Pin_B1);

}
}


//Display Digit 2

void setdigit2(int8 user1)
{
if(user1==0)
{
output_low(Pin_B2);
output_low(Pin_B3);
output_low(Pin_B4);
output_low(Pin_B5);
}

if(user1==1)
{
output_high(Pin_B2);
output_low(Pin_B3);
output_low(Pin_B4);
output_low(Pin_B5);
}

if(user1==2)
{
output_low(Pin_B2);
output_high(Pin_B3);
output_low(Pin_B4);
output_low(Pin_B5);
}

if(user1==3)
{
output_high(Pin_B2);
output_high(Pin_B3);
output_low(Pin_B4);
output_low(Pin_B5);
}

if(user1==4)
{
output_low(Pin_B2);
output_low(Pin_B3);
output_high(Pin_B4);
output_low(Pin_B5);
}

if(user1==5)
{
output_high(Pin_B2);
output_low(Pin_B3);
output_high(Pin_B4);
output_low(Pin_B5);
}

if(user1==6)
{
output_low(Pin_B2);
output_high(Pin_B3);
output_high(Pin_B4);
output_low(Pin_B5);
}

if(user1==7)
{
output_high(Pin_B2);
output_high(Pin_B3);
output_high(Pin_B4);
output_low(Pin_B5);
}

if(user1==8)
{
output_low(Pin_B2);
output_low(Pin_B3);
output_low(Pin_B4);
output_high(Pin_B5);
}

if(user1==9)
{
output_high(Pin_B2);
output_low(Pin_B3);
output_low(Pin_B4);
output_high(Pin_B5);
}
}

//Display Digit 3

void setdigit3(int8 user0)
{
if(user0==0)
{
output_low(Pin_A6);
output_low(Pin_A7);
output_low(Pin_A0);
output_low(Pin_A1);
}

if(user0==1)
{
output_high(Pin_A6);
output_low(Pin_A7);
output_low(Pin_A0);
output_low(Pin_A1);
}

if(user0==2)
{
output_low(Pin_A6);
output_high(Pin_A7);
output_low(Pin_A0);
output_low(Pin_A1);
}

if(user0==3)
{
output_high(Pin_A6);
output_high(Pin_A7);
output_low(Pin_A0);
output_low(Pin_A1);
}

if(user0==4)
{
output_low(Pin_A6);
output_low(Pin_A7);
output_high(Pin_A0);
output_low(Pin_A1);
}

if(user0==5)
{
output_high(Pin_A6);
output_low(Pin_A7);
output_high(Pin_A0);
output_low(Pin_A1);
}

if(user0==6)
{
output_low(Pin_A6);
output_high(Pin_A7);
output_high(Pin_A0);
output_low(Pin_A1);
}

if(user0==7)
{
output_high(Pin_A6);
output_high(Pin_A7);
output_high(Pin_A0);
output_low(Pin_A1);
}

if(user0==8)
{
output_low(Pin_A6);
output_low(Pin_A7);
output_low(Pin_A0);
output_high(Pin_A1);
}

if(user0==9)
{
output_high(Pin_A6);
output_low(Pin_A7);
output_low(Pin_A0);
output_high(Pin_A1);
}
}

/*
void comparetemp(int user2, int user1, int user0, int actual2, int actual1, int actual0)
{
do
{
output_high(Pin_B6);
//calculatetemp(actual2, actual1, actual0);
checkpushbutton(user2, user1, user0, check);

if(check==true)
{
setdigit1(actual2);
setdigit2(actual1);
setdigit3(actual0);
}

else
{
setdigit1(user2);
setdigit2(user1);
setdigit3(user0);
}

}while((actual2==user2 && actual1==user1 && actual0<user0) || (actual2==user2 && actual1<user1 && actual0==user0) ||(actual2<user2 && actual1==user1 && actual0==user0));

output_low(Pin_B6);
}
*/
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Apr 14, 2006 12:52 am     Reply with quote

Its too hard to read your code. Edit your message and to include [c0de] (use o not 0) at the start of your code and [/c0de] (use o not ).

Also you code is far too long. Chop it down and post the smallest code segment that demonstrates your problem.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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