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

setting pin values on a 16f74

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



Joined: 27 Feb 2006
Posts: 20

View user's profile Send private message

setting pin values on a 16f74
PostPosted: Wed Apr 05, 2006 12:31 pm     Reply with quote

Hi there, i sorry to bother ye with such a small problem but im stumped, i am trying to make a sim card reader using a pic, and ive been stumped at the first obstacle.
Essentially all i want to accomplish at the moment is the ability to set pins high and other pins low and no matter what code i implement it seems that all the pins are floating. they are being governed to the devices that they are attached to and not grounding or driving the lines high like i would like i am using the following code
Code:

#include <16F74.h>
#device adc=8
#fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=4915200)

//----------------------------------------------------------------------
#include "C:\finbar\elxproject\PINTEST.h"


void main()
{
   #use rs232(baud=9600, parity=n, bits=8, xmit=pin_a1, rcv=pin_a4, errors)
   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   output_low(pin_B1);    //RST is in state L
   delay_us(10);
   output_high(pin_B2);    //VCC is set to high
   delay_us(10);
   output_high(pin_B0);    //VPP is raised to idle
   delay_us(10);
   output_low(pin_B7);    //I/O transmit to card set to off---(receive from card enabled)---
   delay_us(10);
   output_high(PIN_B3);
   OUTPUT_HIGH(PIN_A0);
   OUTPUT_HIGH(PIN_A1);
   OUTPUT_LOW(PIN_A2);
   OUTPUT_HIGH(PIN_A3);
   OUTPUT_LOW(PIN_A4);

}



is there any reason why these pins are not doing what i am telling them to do?
cheers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 12:48 pm     Reply with quote

It's very likely that you have a "#use fast_io" statement in that
pintest.h file.

Get rid of the #use fast_io() statement. As a newbie, you don't need it.
CCS will automatically set the correct TRIS for you, if you use their i/o
functions, such as output_low(), output_high(), etc.

Also, read other posts on this forum. Look at the sample code posted.
You'll notice that certain forms are used. Don't put your #use rs232
statement inside main(). Move it up so it's just after the #use delay().
Also, if you look at other people's code, you'll notice that they don't let
their program fall off the end of main(). I put a while(1); statement
at the end of main().

I think you're using the CCS wizard. I believe it creates these little ".h"
files. In my opinion, this is very bad. It hides important information
from a newbie.
ninebarmaximus



Joined: 27 Feb 2006
Posts: 20

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 2:25 pm     Reply with quote

im afraid its even more pressing a matter than that, at the top i have shown the contents of the header file, before the rest of the code, i changed the code to do a simple operation of just turning pin a1 on and off and that wont work either, i have both vss pins high, both gnd low and vpp high and thats all ive connected and my pic just sits there, is there something very simple im missing here, this is simpler code that also will not work
[code]
#include <16F74.h>
#device adc=8
#fuses NOWDT,LP, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=20000)

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

do {
if (output_high(PIN_A3))
{
delay_ms(1000);
output_low(PIN_A3);
}
else
{
delay_ms(1000);
output_high(PIN_A3);
}
if (output_high(PIN_A1))
{
delay_ms(1000);
output_low(PIN_A1);
}
else
{
delay_ms(1000);
output_high(PIN_A1);
}
}while (1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 05, 2006 2:38 pm     Reply with quote

You've changed to LP mode and you're running at 20 KHz ?
What happened to the 4.9 MHz crystal ?

Your program is still way, way too complicated.
See the following post for an example of a simple program:
http://www.ccsinfo.com/forum/viewtopic.php?t=19199&start=1
ninebarmaximus



Joined: 27 Feb 2006
Posts: 20

View user's profile Send private message

PostPosted: Thu Apr 06, 2006 11:37 am     Reply with quote

tried that simple program that you sent me, works a treat. It seems that if i put anything in an if statement it doesnt work, could someone just give me a few lines of code.

maybe just a simple thing to turn a led on and off, and then an if statment after it to see if that led is lit light another.

i dont know why my if statment isnt working

someone please help
this is the code im using to see if i can get an if statment working
Code:

#include <16F74.h>
#device adc=8
#fuses NOWDT,XT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=4000000)



void main()
{

   while(1) {
         output_high(PIN_A0);
      delay_ms(500);
      
      if (output_high(PIN_A0))
      {
      delay_ms(500);
      output_high(PIN_A2);
      }
      output_low(PIN_A0);
      delay_ms(500);
   }
   
   

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 06, 2006 11:47 am     Reply with quote

The input() function is used to read a pin, not the output_high() function.

Also, you don't normally read a pin that you're also setting high or low.
You read one pin, and set a different pin high or low (or take some other
action in the program).
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