View previous topic :: View next topic |
Author |
Message |
theredkid
Joined: 27 Aug 2014 Posts: 14
|
What's wrong? |
Posted: Thu Sep 04, 2014 12:32 am |
|
|
Hello,
I successfully compiled the following prg but but couldn't run it. Do you think I should include the config bits?
Code: |
#include <18f452.h>
#FUSES XT,NOWDT,NOPROTECT,NOLVP,NOPUT,NOBROWNOUT,NOOSCSEN,NOSTVREN,NODEBUG,NOWRT,NOWRTD,NOWRTB,NOWRTC,NOCPD,NOCPB,NOEBTR,NOEBTRB
#use delay (clock=4000000)
#define R_CZ pin_b0
#define S_CZ pin_b1
#define T_CZ pin_b2
#define R_tetY pin_e2
#define R_tetY_ pin_c1
#define S_tetY pin_c3
#define S_tetY_ pin_c4
#define T_tetY pin_c5
#define T_tetY_ pin_e0
//#use fast_io(b) //
int1 R=0;
int1 S=0;
int1 T=0;
int1 a=0;
int R1d=0;
int R2d=0;
int S1d=0;
int S2d=0;
int T1d=0;
int T2d=0;
int delay=100;
//****************** Timer0 *****************************
#int_timer0
void timer0_kesme ()
{
set_timer0(254);
//////////////////////////////////////////////////
if (R1d)
{
R1d--;
if (R1d==0)
output_low(R_tetY);
}
if (R2d)
{
R2d--;
if (R2d==0)
output_low(R_tetY_);
}
///
if (S1d)
{
S1d--;
if (S1d==0)
output_low(S_tetY);
}
if (S2d)
{
S2d--;
if (S2d==0)
output_low(S_tetY_);
}
///
if (T1d)
{
T1d--;
if (T1d==0)
output_low(T_tetY);
}
if (T2d)
{
T2d--;
if (T2d==0)
output_low(T_tetY_);
}
//////////////////////////////////////////////////
a = input(R_CZ);
if (R!=a)
{
if (a)
{
output_high(R_tetY);
R1d=delay;
}
else
{
output_high(R_tetY_);
R2d=delay;
}
R=a;
}
////
a = input(S_CZ);
if (S!=a)
{
if (a)
{
output_high(S_tetY);
S1d=delay;
}
else
{
output_high(S_tetY_);
S2d=delay;
}
S=a;
}
////
a = input(T_CZ);
if (T!=a)
{
if (a)
{
output_high(T_tetY);
T1d=delay;
}
else
{
output_high(T_tetY_);
T2d=delay;
}
T=a;
}
}
void main ( )
{
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_4);
set_timer0(254);
enable_interrupts(INT_timer0);
enable_interrupts(GLOBAL);
output_low(R_tetY);
output_low(R_tetY_);
output_low(S_tetY);
output_low(S_tetY_);
output_low(T_tetY);
output_low(T_tetY_);
while(1)
{
}
} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Sep 04, 2014 2:55 am |
|
|
A few questions.
1) Compiler version?
2) Real hardware or Proteus/ISIS.
3) How are your switches wired?
4) What do you expect to happen?
5) Can you get a simple LED flasher to work at the correct speed?
Mike |
|
|
theredkid
Joined: 27 Aug 2014 Posts: 14
|
|
Posted: Thu Sep 04, 2014 3:16 am |
|
|
1) CCS C MPLAB IDE v8.92
2) Real Hardware
3) PIC KIT 3
4) This is a PIC software to control 3 phase thyristor triggering.
5) No LED flash. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Sep 04, 2014 7:17 am |
|
|
crawl before you run !!
first confirm that you can flash the LEDs with a simple program like the 1Hz LED test.
A simple toggle LED, delay 1/2 second, repeat.
recode/recompile/retest/report back if that is successful !
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Sep 04, 2014 7:20 am |
|
|
1) That is NOT your CCS C Compiler version. Spend some time on the forum to learn what this question *really* means.
2) Please post a picture of your hardware
3) Your reply has nothing to do with the question asked
4) This is now your third thread on this topic.
5) Learn to test your basic hardware by performing a simple LED flashing program. Your program is really silly! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Sep 04, 2014 8:04 am |
|
|
PLEASE put in meaningful subjects.
I can't stress how subtly important this is.
If you can't take the time to do so, why should anyone take the time to look at your problem? _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
theredkid
Joined: 27 Aug 2014 Posts: 14
|
|
Posted: Thu Sep 04, 2014 9:34 am |
|
|
ezflyr wrote: | 1) That is NOT your CCS C Compiler version. Spend some time on the forum to learn what this question *really* means.
2) Please post a picture of your hardware
3) Your reply has nothing to do with the question asked
4) This is now your third thread on this topic.
5) Learn to test your basic hardware by performing a simple LED flashing program. Your program is really silly! |
- How come you know my prg is silly? It's for controlling 3 phase thyristor triggering sequence. If u think my prg is silly, then u r supposed to know a smarter version. Would you mind share it here? |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Sep 04, 2014 10:57 am |
|
|
Hi,
Frankly, it's hard to know where to start!
Right now, you say 'No LED flash', but do you even know that your PIC is running, and running at the correct frequency? You need to create a simple test program that does nothing else except toggle a single LED at a known frequency. Turn the LED On for one second, and then Off for one second. Do this in a loop with delays, do not use timers! This has been covered many, many times before. Your program is currently not working at all, so you need to drastically simplify it to test the basics first!
Your variable names are really bad! Come on, can't you come up with nothing more descriptive than 'R', 'S', and 'T', etc.? A lack of descriptive variable names leads to code like this:
Code: |
if (T!=a)
{
if (a)
{
|
which is virtually unreadable code. While trying to understand your code I found myself getting dizzy with my eyes crossing......
Your code structure is really poor! This has been covered many, many times, and I think mentioned to you in one of your other threads, you want to keep your interrupt handlers as short as possible, and do all your processing in Main(). Use the interrupt handler to set a flag, change a variable, etc. and then do everything else in Main().
Finally, your code has zero comments. You come here asking for our help, and then expect us to wade thru a maze of cryptic, undocumented code??
John |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 04, 2014 11:08 am |
|
|
Your board schematic that you posted here,
http://oi57.tinypic.com/2mxfm7r.jpg
is missing the 22 pf capacitors on the crystal. Nothing is going to work
until you fix that. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
What's wrong |
Posted: Thu Sep 04, 2014 1:41 pm |
|
|
I'm in a good mood, so I'll settle for almost everything.
Mike |
|
|
|