Author Topic: CCS C help  (Read 12292 times)

0 Members and 1 Guest are viewing this topic.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
CCS C help
« on: October 02, 2008, 05:39:01 AM »
hello guys.i'm tring to write a small code to blink a led using PIC12F675 using CCS C Compiler v4.057 (PIC C compiler).
here is my code

Code: [Select]
#include "C:\Documents and Settings\Aruna\Desktop\pic c\aa\a.h"
#include <stdio.h>

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_18MS);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   while(1)
   {
   output_high(PIN_A3);
   delay_ms(1000);
   output_low(PIN_A3);
   delay_ms(1000);
   }

}

but i cant get this code compiled it gives following error in header file

Code: [Select]
Error 111 "C:\Documents and Settings\Aruna\Desktop\pic c\aa\a.h" Line 11(7,46):unknown keyword in #FUSES "BORSEN"/code]

here is my complete header file

[code]#include <12F675.h>
#device adc=8

#FUSES WDT                      //Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORSEN                 //See Datasheet

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A2,bits=8)

please help me[/code]
I'm Me

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: CCS C help
« Reply #1 on: October 02, 2008, 11:25:25 AM »
Lines similar to the following should be the first lines in your main C file:

#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

Give that a try.  Obviously, tailor this to your situation.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: CCS C help
« Reply #2 on: October 02, 2008, 11:31:00 AM »
Lines similar to the following should be the first lines in your main C file:

#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

Give that a try.  Obviously, tailor this to your situation.

thanks it works
anyway i tried it with
Code: [Select]
#use delay(clock=4000000) that is 4MHz.is it ok to use 20MHz?
I'm Me

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: CCS C help
« Reply #3 on: October 02, 2008, 02:13:46 PM »
You need to set the delay clock to whatever your crystal / resonator is.
Check your part specs to see if your chip can be driven at 20MHz.  Go to where you ordered your chip and check the part number.  Typical max frequencies are 4 MHz, 10 MHz and 20 MHz.
In the future, only order 20 MHz parts if you didn't this time.  There's no reason to order the slower parts unless you're coding in assembly.

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: CCS C help
« Reply #4 on: October 02, 2008, 02:16:02 PM »
I checked Mouser for 12F675 parts.  They are all 20 MHz parts there.  Yours probably is too.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: CCS C help
« Reply #5 on: October 02, 2008, 08:21:59 PM »
I checked Mouser for 12F675 parts.  They are all 20 MHz parts there.  Yours probably is too.

ya it supports 20MHz and i use internal oscillator.is there any advantage of using an external oscillator?
and can you point me somewhere i can get example source codes fo 12F675?
Thanks ::)
I'm Me

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: CCS C help
« Reply #6 on: October 03, 2008, 07:26:54 AM »
Yes.  There is an advantage.  External oscillators (in the form of ceramic resonators or crystals) are much more accurate timing sources, especially crystals.  If you are doing a project that requires accurate timing, this will become important to you.

Google is your friend for finding PIC projects, but I like the many books that are available for PIC projects.

I did have this site bookmarked.

http://www.best-microcontroller-projects.com/index.html

The 12F675 is an awesome little chip.  When I was your age, I had to wrestle with 555 timers just to get a square wave...  And I had to walk to school, uphill both ways.


Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: CCS C help
« Reply #7 on: October 03, 2008, 09:49:08 AM »
Yes.  There is an advantage.  External oscillators (in the form of ceramic resonators or crystals) are much more accurate timing sources, especially crystals.  If you are doing a project that requires accurate timing, this will become important to you.

Google is your friend for finding PIC projects, but I like the many books that are available for PIC projects.

I did have this site bookmarked.

http://www.best-microcontroller-projects.com/index.html

The 12F675 is an awesome little chip.  When I was your age, I had to wrestle with 555 timers just to get a square wave...  And I had to walk to school, uphill both ways.


cool thanks
I'm Me

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: CCS C help
« Reply #8 on: October 03, 2008, 10:38:38 AM »
@arcman
i'm tring to learn about PWM.i'm tring to increase and decrease brightnes of a led sin PWM(i guess).code seems working but i cant get linear brightness change.i can see led is blinking at different brightness levels .I dont know how to use time intervals.(check my code to see how i did it)
this is my code
Code: [Select]
#include "D:\PIC C codes\PWM1\pwm1.h"

#include <12F675.h>
#device adc=10
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A2,bits=8)
#byte OSCCAL = 0x80
int x=0;


void pwm(int a)
{
if(a==1)
output_high(PIN_A1);

if(a==2)
{
output_high(PIN_A1);
delay_us(87.5);
output_low(PIN_A1);
delay_us(12.5);
}

if(a==3)
{
output_high(PIN_A1);
delay_us(75);
output_low(PIN_A1);
delay_us(25);
}

if(a==4)
{
output_high(PIN_A1);
delay_us(62.5);
output_low(PIN_A1);
delay_us(37.5);
}

if(a==5)
{
output_high(PIN_A1);
delay_us(50);
output_low(PIN_A1);
delay_us(50);
}

if(a==6)
{
output_high(PIN_A1);
delay_us(37.5);
output_low(PIN_A1);
delay_us(62.5);
}

if(a==7)
{
output_high(PIN_A1);
delay_us(25);
output_low(PIN_A1);
delay_us(75);
}

if(a==8)
{
output_low(PIN_A1);
}
}


void main()
{

   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(AN0_ANALOG);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   set_adc_channel(0);
   
   while(1)
   {
   delay_ms(10);
   x=read_adc();
   
   if(x>=0 && X<31)
   pwm(8);
   
   if(x>=31 && X<63)
   pwm(7);
   
   if(x>=63 && X<95)
   pwm(6);
   
   if(x>=95 && X<127)
   pwm(5);
   
   if(x>=127 && X<159)
   pwm(4);
   
   if(x>=159 && X<191)
   pwm(3);
   
   if(x>=191 && X<223)
   pwm(2);
   
   if(x>=223 && X<255)
   pwm(1);
   
   }

}

i googled for this and found a artical on best-microcontroller-project site.but that artical ddnt help me much and i does not show the source code.can you show me the error and point me to a complete PWM tutorial? or can you post me a code(in CCS C) that can be used to do my job?(so i can read it and understand how it works and how to build a PWM code).
so please help me.
thanks

PS:off topic:
can i use opto isolator(attached zip file) to short 2 pins of a motor for breaking?(i use home made 4 transistor h-bridge) or do i have to use relay orreed switch for this?
« Last Edit: October 03, 2008, 11:45:54 AM by aruna1 »
I'm Me

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: CCS C help
« Reply #9 on: October 08, 2008, 05:12:29 AM »
Quote
can i use opto isolator(attached zip file) to short 2 pins of a motor for breaking?
Generally, shorting something involves high currents to pass through. It depends on your circuit, and the power specs/requirements of your hardware.

I think it would be better to use a motor driver.

 


Get Your Ad Here