View previous topic :: View next topic |
Author |
Message |
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
need help for c programming for digital wattmeter. |
Posted: Wed Apr 06, 2011 4:11 pm |
|
|
hai everyone.. I hope somebody can help me in ccs programming for digital wattmeter. I'm using PIC18F845. now when i compile i got 100 warning. it told me that the error come from stdlib.h. can somebody help me.. pleaseee!!!.. _________________ i'm student that realy need help to learn |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 06, 2011 5:35 pm |
|
|
There is no 18F845.
Also, your program must be written for the CCS compiler.
If it's written for Microchip C18 or some other compiler, it will not compile
correctly with the CCS compiler.
Post a link to your source code. |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 1:32 am |
|
|
sir.. Here my the link for my code word. Hope you can really help me. I'm about to crying when I see 100 errors. pls help me sir.
http://www.mediafire.com/?c13140esi24dc64 _________________ i'm student that realy need help to learn |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 3:43 am |
|
|
I have change my PIC to PIC16f870. _________________ i'm student that realy need help to learn |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Apr 07, 2011 5:49 am |
|
|
Well I looked at your program...
1)You're NOT using CCS C.
2)glaring error..
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <18F458.h>
the line with the processor MUST be the first one......
2a) also need #use delay(clock=...) statement
3)Get rid of ALL the ..tris.. statements and let the compiler do it AUTOMATICALLY for you ( you have errors)
4)LCD commands won't do anything, you have no driver code for it
5)msdelay(xx) is not a valid CCS function
6)ALL ADC functions, variables are NOT CCS
7)LongToSTR(..) not a valid CCS function
8)use of floating point math
9)no debounce in the keypad routine
10) MAIN() never ends, just loops forever setting ADC bits (wrongly), will never display results on LCD (which hasn't a driver).
these are just some of the obvious errors...
Instead of cut/paste from another program, I suggest you look at the examples that CCS kindly supplies and build from there. Start with the classic 'hello World' LCD program, then add the ADC task (simple NOT full of math), then the keypad task.
While you have a project open, you can press F11 to access the CCS onscreen manual, great to lookup most of what you need to use CCS C.
Also, if using MPLAB to burn your PICs, you'll have to go to Build Configuration and select 'release' THEN compile your code. |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 6:10 am |
|
|
thank you sir.. now what should i do.. sorry for that question.. i'm newbie.. _________________ i'm student that realy need help to learn |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Apr 07, 2011 7:01 am |
|
|
temtronic already told you what to do.
Quote: | Instead of cut/paste from another program, I suggest you look at the examples that CCS kindly supplies and build from there. Start with the classic 'hello World' LCD program, then add the ADC task (simple NOT full of math), then the keypad task. |
Start with writing a "Hello World" program in CCS C using the CCS examples. Then add one little bit at a time till you get the program you need. Baby steps will get you there without falling off a cliff. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 8:31 am |
|
|
thank you for the comment sir. I will try to do it again from the bottom.. later I will post my code word. Hope you can check my code word later.. please sir.. :-( _________________ i'm student that realy need help to learn |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 1:25 pm |
|
|
hye everyone.. I got something to ask.. now I'm done for doing hello world code. And now I want to do subfunction for current and voltage measuring and keypad function. My question is how to do sub function in this ccs compiler? Can someone give me the answer please.
Here is my code.
Code: |
#include <16F870.h>
#device adc=8
#define CLKSPEED 32000000
#define current PIN_A1
#define voltage PIN_A2
#fuses NOWDT, XT, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=CLKSPEED)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#include "flexlcd.c"
//====================================
void main(void)
{
lcd_init();
set_tris_A(0xff);
set_tris_C(0x00);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
lcd_putc("Digital Wattmeter");
while(1);
} |
_________________ i'm student that realy need help to learn |
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Thu Apr 07, 2011 1:43 pm |
|
|
miji88 wrote: | hye everyone.. I got something to ask.. now im done for doing hello world code. and now i want to do subfucntion for current and voltage measuring and keypad function. my question is how to do sub fucntion in this ccs compiler? can someone give me the answer please..
here is my code. |
This might help you: http://www.ehow.com/how_2056296_declare-function-c.html |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Apr 07, 2011 2:34 pm |
|
|
Ok, now you're better
but
get RID of the use_fast_io() AND set tris commands
Let the compiler do those for you AUTOMATICALLY.
As you said, you are NEW and using those commands are for experienced programmers for special situations. 99.9% of the time you will NOT need to use them. Maybe in 10-15 years and 100-120 project later, you, might, need to use them but NOT now.
I suggest you look at ADC examples and use a pot for the 'sensor' and get the display to show the ADC result using the printf(.......) command.
That should take you a couple of days, as it can be complicated to get exactly what you want. You'll like the lcd gotoxy commands as you can put volt in one corner, watts in the other on the second line, with titles on the first.
If you get that done in less than a week you're doing great ! Especially if English is not your first language. |
|
|
miji88
Joined: 06 Apr 2011 Posts: 25 Location: Malaysia
|
|
Posted: Thu Apr 07, 2011 8:24 pm |
|
|
ok sir. I'll try to do that.. but i need this program to be done in this two weeks.. hope you always can help me.. _________________ i'm student that realy need help to learn |
|
|
necati
Joined: 12 Sep 2003 Posts: 37 Location: istanbul
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Apr 08, 2011 11:58 am |
|
|
This project needs to be done in two weeks??? That's unfortunate. That's absolutely no time to LEARN anything. That's like trying to take a gallon of water and drinking it in one big GULP instead of one swallow at a time. Keep it as simple as possible. Cutting/pasting from somebody else's code will only cause you grief and confusion. Start simple with ONE task. Once you have that task working, add another. Build on to that until you have what you want finished. Keep it simple and try to learn!
Ronald |
|
|
|