|
|
View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
output_c on 16F1823 with 4.123 |
Posted: Tue Dec 06, 2011 9:52 am |
|
|
If I try to use the output_c function of the compiler for the 16F1823 controller I can't compile my code. It's the EX_STEP.c example file which I want to change to the 16F1823 controller. Does anyone know why it isn't working?
Compiler version: 4.123
Code: | #include <16F1823.H>
#FUSES INTRC_IO,NOWDT
#FUSES PUT,NOMCLR,PROTECT,NOCPD,BROWNOUT,BORV25
#FUSES NOCLKOUT,NOIESO
#FUSES NOFCMEN,WRT
#FUSES PLL_SW,NOSTVREN,NODEBUG,NOLVP
#Device ADC=8
#use delay(clock=4000000)
BYTE const POSITIONS[4] = {0b0101,
0b1001,
0b1010,
0b0110};
//#define DATA PIN_A0
//#define CLK PIN_A1
#define RESET PIN_A2
//#define MCLR PIN_A3
//#define INPUT PIN_A4 ANALOOG sAN3
#define EINDSCHAKELAAR PIN_A5
#define OUT1 PIN_C0
#define OUT2 PIN_C1
#define OUT3 PIN_C2
#define OUT4 PIN_C3
#define LED1_UIT PIN_C4
#define LED2_UIT PIN_C5
drive_stepper(BYTE speed, char dir, BYTE steps) {
static BYTE stepper_state = 0;
BYTE i;
for(i=0; i<steps; ++i) {
delay_ms(speed);
set_tris_c(0xf0);
OUTPUT_C = POSITIONS[ stepper_state ];
if(dir!='R')
stepper_state=(stepper_state+1)&(sizeof(POSITIONS)-1);
else
stepper_state=(stepper_state-1)&(sizeof(POSITIONS)-1);
}
}
use_pot() {
BYTE value;
setup_adc(adc_clock_internal);
set_adc_channel( 1 );
while( TRUE ) {
value=read_adc();
if(value<0x80)
drive_stepper(value,'R',8);
else if(value>0x80)
drive_stepper(128-(value-128),'F',8);
}
}
use_switch(BYTE speed, char dir) {
BYTE steps;
while(true) {
while(input(RESET)) ;
drive_stepper(speed,dir,steps);
while(!input(RESET)) ;
delay_ms(100);
}
}
main() {
setup_oscillator(OSC_4MHZ);
setup_dac(DAC_OFF);
setup_vref(VREF_OFF);
setup_adc_ports(sAN3|VSS_VDD); //A4 = AN3 = AC input
setup_adc(ADC_CLOCK_DIV_8); // Built-in A/D setup function TAD is 2µSec
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128); // 32,8 ms tot overflow (0.25us*4*128*256)
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // 8us per ophoging van timer1
setup_timer_2(T2_DIV_BY_1, 255, 1); // Setup for 8 bit at 4kHz
T1GSEL = 0; // T1_GATE_A4 instructie doet het niet vandaar handmatig.
TXCKSEL = 1;
BYTE speed, steps;
char dir;
while(1)
{
if(speed==0)
use_pot();
if(steps==0)
use_switch(speed,dir);
drive_stepper(speed,dir,steps);
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Dec 06, 2011 10:25 am |
|
|
First, I'd create a simple 'toggle LED on a portC pin' before modifying other programs.
This will verify that the PIC is physically configure correctly. You do have current limiting resistors for the LEDs ?! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Tue Dec 06, 2011 10:52 am |
|
|
Comments:
1) C does not support 'mid function' variable declaration. Variables _must_ be declared at the start of the function, or code block. CCS, does not complain about this, and will 'sometimes' accept this, but _not_ reliably.
2) Look in the manual for the syntax of 'output_c'. What you have is _not_ right. In C, '=' assigns a value to a variable. It doesn't send a value to a function....
Best Wishes |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Wed Dec 07, 2011 1:49 am |
|
|
It's compiling when I change the sentence to
Code: |
output_c(POSITIONS[ stepper_state ]);
|
Now I'm going to make the hardware to test the program. Thanks. |
|
|
|
|
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
|