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 support@ccsinfo.com

a very basic code not working? 16F870

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



Joined: 16 Feb 2005
Posts: 25

View user's profile Send private message

a very basic code not working? 16F870
PostPosted: Wed Feb 08, 2006 11:59 am     Reply with quote

I have used (Mplab, picstartplus, CCS c compiler) a while ago, now kind of of lost touch completely...please help what am I doing wrong?


Code:
#include <16f870.h>
#device adc=8
#use delay(clock= 4000000, restart_wdt)
#fuses NOWDT, XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT
#include <math.h>

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

void main () {

  set_tris_a(0b00111110);
  set_tris_b(0b11111100);
  set_tris_c(0b00000000);         

  setup_adc(ADC_CLOCK_INTERNAL);
  setup_adc_ports(NO_ANALOGS);
 
  output_low(PIN_B1); 

  while (TRUE) {     
    output_high(PIN_B1);
    delay_ms(10);
  }
}



just to be sure

pin 1 - pulled high to vdd (5V) using 5.1K rresistor
8 and 19 - ground
9 and 10 - 4MHz crystal and 33pF caps as shown in data sheet
20 vdd(5V)

I couldnot see HIGH (5V) on PIN_B1 what the heck....

I have programmed before and made few working circuits, this is killing me...

what could go wrong?

thx
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 08, 2006 12:16 pm     Reply with quote

I changed the header and a little of the code. This works.
I don't think the code is bad.
Check MCLR and clock. The caps should agree with the crystal's spec sheet. NOT and arbitrary schematic. Does that make sense?
Code:
#include <16F877a.h>
#device *=16   //not needed for now.
#use delay(clock=4000000)
#fuses hs,nowdt,nolvp,protect,put,brownout
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7) // STDERR(same as DEBUG)
#case
#zero_ram

//#include <16f877a.h>
//#device adc=8
//#use delay(clock= 4000000, restart_wdt)
//#fuses NOWDT, XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT
#include <math.h>

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

void main () {

  set_tris_a(0b00111110);
  set_tris_b(0b11111100);
  set_tris_c(0b00000000);

  setup_adc(ADC_CLOCK_INTERNAL);
  setup_adc_ports(NO_ANALOGS);

  output_low(PIN_B0);
  output_high(PIN_B0);

  while (TRUE) {
    output_toggle(PIN_B0);
    output_toggle(PIN_B1);
    delay_ms(1000);
  }
}
digitalfreak



Joined: 16 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Wed Feb 08, 2006 12:48 pm     Reply with quote

thx treitmey for your response....

NOW changed to PIC 16F876A, using 20MHz crstal with 33pF. I still could not see output high on B1.

I see 5V at MLCR , clock is good (checking volatge at pins 9 and 10 ~2.5, ~2.4)

Code:
#include <16F876A.h>
#device adc=16
#use delay(clock=20000000)
#fuses NOWDT, HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7) // STDERR(same as DEBUG)
#case
#zero_ram
#include <math.h>

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

void main () {

  set_tris_a(0b00111110);
  set_tris_b(0b11111100);
  set_tris_c(0b00000000);         

  setup_adc(ADC_CLOCK_INTERNAL);
  setup_adc_ports(NO_ANALOGS);
 
  output_low(PIN_B0);
  output_high(PIN_B1); 

  while (TRUE) {     
    output_toggle(PIN_B0);
    output_toggle(PIN_B1);
    delay_ms(1000);
  }
}


Iam just trying to see HIGH on at least one pin to make sure things are working to start my project....I could not EVEN GET STARTED...

help...
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 08, 2006 1:42 pm     Reply with quote

This code works. Can't get much smaller. I have the wrong freq and wrong chip and it still works for me. Have you put +5 and ground all the places it needs to be?
Code:
#include <16F876A.h>
#use delay(clock=20000000)
#fuses HS,NOLVP
void main () {
  output_high(PIN_B0);
  while (TRUE) {
  }
}
digitalfreak



Joined: 16 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Wed Feb 08, 2006 2:17 pm     Reply with quote

thanks treitmey

no change in circuitry .... works brilliant.!! now need to jump start on things...i still donot know whats wrong with previous code?

thanks again...
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