|
|
View previous topic :: View next topic |
Author |
Message |
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
#BYTE register declaration |
Posted: Wed Dec 18, 2013 12:30 pm |
|
|
Hello all,
CCS Version : CCS PCD C Compiler, Version 5.006, 7054
Chip used : DSPIC33FJ09GS302
In my program, I declare two registers :
#BYTE CMPCON1 = 0x0540
#BYTE CMPCON2 = 0x0544
and, a little further, I affect values to them :
CMPCON1 = 0x8585;
CMPCON2 = 0x0485;
but, here is what the compiler has traducted (in .lst file) :
.................... CMPCON1 = 0x8585;
03D0: MOV.B #85,W0L
03D2: MOV.B W0L,540
.................... CMPCON2 = 0x0485;
03D4: MOV.B #85,W0L
03D6: MOV.B W0L,544
It writes 8 bit value, and I've asked for a 16 bit value. I imagine that I wrote something wrong.
Can you help me dealing this problem ?
Here is the whole code (it is in debugging state) :
Code: | #include <33FJ09GS302.h>
//// Historique des version
////
//// 1.00 : Initial version
////
//
//// Definition FUSES
#FUSES ICSP1 // ICD uses PGC1/PGD1 pins
#FUSES NOJTAG // JTAG disabled
#FUSES DEBUG // Debug mode for use with ICD
//#FUSES WPOSTS1 // Watch Dog Timer PostScalar 1:1
#FUSES PLLWAIT //Clock switch will wait for the PLL lock signal
#FUSES NOWDT // No Watch Dog Timer
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES NOWRT //Program memory not write protected
#FUSES NOPROTECT //Code not protected from reading
#USE DELAY (clock=7370000)
#USE RS232(BAUD=9600, XMIT=PIN_B1, RCV=PIN_B0, STREAM=COM_A)
#BYTE CMPCON1 = 0x0540
#BYTE CMPDAC1 = 0x0542
#BYTE CMPCON2 = 0x0544
#BYTE CMPDAC2 = 0x0546
//
//// Affectation des signaux
#define LED_BLINK PIN_A1
#define TRIGGER_ENABLE PIN_B5
#define POWER_ENABLE PIN_B15
#define TIMER1_VALUE 0x8FF2 // 50 ms
#define TIMER2_VALUE 0x8FF2 // 50 ms
#define TICK_BLINK_LED 50
////////////////////////
// Variables Globales //
////////////////////////
enum
{
RS232_WAITING = 0,
RS232_COMMAND = 1,
RS232_HARG = 2,
RS232_LARG = 3,
RS232_END = 4,
RS232_TIMEOUT = 10
} RS232_serial_state = 0;
unsigned int16 tick_counter_blink_led; // compteur clignotement leds
int1 bStateBlinkingLed; // Indicateur état led clignottante
unsigned int8 SerialCommand;
unsigned int8 SerialHArg;
unsigned int8 SerialLArg;
int1 NouvelleCommandeRS232;
///////////////////////////
// CONFIGURATION DSPIC33 //
///////////////////////////
#USE FAST_IO(a)
#USE FAST_IO(b)
////////////////////////////
// Routine d'interruption //
////////////////////////////
#INT_TIMER1
void timer1_interrupt_handler()
{
// Le timer est réglé pour ticker toutes les 50 ms
set_timer1(TIMER1_VALUE);
// Gestion led clignotante
tick_counter_blink_led ++;
if(tick_counter_blink_led > TICK_BLINK_LED)
{
bStateBlinkingLed ++;
tick_counter_blink_led = 0;
}
}
#INT_TIMER2
void timer2_interrupt_handler()
{
if(RS232_serial_state != RS232_WAITING)
{
RS232_serial_state = RS232_TIMEOUT;
}
}
#INT_RDA
void RS232_interrupt_handler()
{
char c;
c = fgetc(COM_A);
switch(RS232_serial_state)
{
case RS232_WAITING :
if(c == 0x02) // STX
{
RS232_serial_state = RS232_COMMAND;
set_timer2(TIMER2_VALUE);
}
break;
case RS232_COMMAND :
SerialCommand = c;
RS232_serial_state = RS232_HARG;
set_timer2(TIMER2_VALUE);
break;
case RS232_HARG :
SerialHArg = c;
RS232_serial_state = RS232_LARG;
set_timer2(TIMER2_VALUE);
break;
case RS232_LARG :
SerialLArg = c;
RS232_serial_state = RS232_END;
set_timer2(TIMER2_VALUE);
break;
case RS232_END :
if(SerialCommand == 0x03)
{
NouvelleCommandeRS232 = 1;
}
else
{
NouvelleCommandeRS232 = 0;
SerialCommand = 0;
SerialHArg = 0;
SerialLArg = 0;
}
RS232_serial_state = RS232_WAITING;
break;
case RS232_TIMEOUT :
printf("%x%x",0xFF, 0x02);
NouvelleCommandeRS232 = 0;
SerialCommand = 0;
SerialHArg = 0;
SerialLArg = 0;
RS232_serial_state = RS232_WAITING;
break;
default:
RS232_serial_state = RS232_WAITING;
break;
}
}
/////////////////////////
// Programme principal //
/////////////////////////
void main()
{
unsigned int16 PuissanceEclairage;
int16 iConfigPortA = 1 | // RA0 : ADC_IN
0<<1 | // RA1 : LED_BLINK
0<<2 | // RA2 : GND
0<<3 | // RA3 : GND
0<<4 | // RA4 : GND
0<<5 | // RA5 : Unimplemented
0<<6 | // RA6 : Unimplemented
0<<7 | // RA7 : Unimplemented
0<<8 | // RA8 : Unimplemented
0<<9 | // RA9 : Unimplemented
0<<10 | // RA10 : Unimplemented
0<<11 | // RA11 : Unimplemented
0<<12 | // RA12 : Unimplemented
0<<13 | // RA13 : Unimplemented
0<<14 | // RA14 : Unimplemented
0<<15; // RA15 : Unimplemented
int16 iConfigPortB = 1 | // RB0 : SERIAL_IN
0<<1 | // RB1 : SERIAL_OUT
0<<2 | // RB2 : GND
0<<3 | // RB3 : DAC_OUT
0<<4 | // RB4 : GND
0<<5 | // RB5 : TRIGGER_ENABLE
0<<6 | // RB6 : PGED
0<<7 | // RB7 : PGEC
0<<8 | // RB8 : GND
0<<9 | // RB9 : GND
0<<10 | // RB10 : GND
0<<11 | // RB11 : GND
0<<12 | // RB12 : GND
0<<13 | // RB13 : GND
0<<14 | // RB14 : GND
0<<15; // RB15 : POWER_ENABLE
//// ////
//// Initialisations ////
//// ////
//
//// DAC
int iConfigCMPCON1 = 1 | // RANGE : High range = 1
0<<1 | // CMPPOL : Comparator Output Polarity Control Bit
1<<2 | // HGAIN : DAC Gain Enable bit
0<<3 | // CMPSTAT : Current state of Comparator output
0<<4 | // HYSPOL : Comparator Hysteresis Polarity selection bit
0<<5 | // EXTREF : Internal reference source provide reference to DAC
0<<6 | // INSEL 0 : Select CMPxC input pin
1<<7 | // INSEL 1 : Select CMPxC input pin
1<<8 | // DACOE : DAC Output Enable
0<<9 | // FCLKSEL : Digital filter and pulse stretcher clock selection bit
1<<10 | // FLTREN : Digital filter enable bit
0<<11 | // HYSSEL 0 : Comparator hysteresis select bits
0<<12 | // HYSSEL 1 : Comparator hysteresis select bits
0<<13 | // CMPSIDL : Stop in iddle mode bit
0<<14 | // Unimplemented
1<<15; // CMPON : Comparator Operating Mode bit
int iConfigCMPCON2 = 1 | // RANGE : High range = 1
0<<1 | // CMPPOL : Comparator Output Polarity Control Bit
1<<2 | // HGAIN : DAC Gain Enable bit
0<<3 | // CMPSTAT : Current state of Comparator output
0<<4 | // HYSPOL : Comparator Hysteresis Polarity selection bit
0<<5 | // EXTREF : Internal reference source provide reference to DAC
0<<6 | // INSEL 0 : Select CMPxC input pin
1<<7 | // INSEL 1 : Select CMPxC input pin
0<<8 | // DACOE : DAC Output Enable
0<<9 | // FCLKSEL : Digital filter and pulse stretcher clock selection bit
1<<10 | // FLTREN : Digital filter enable bit
0<<11 | // HYSSEL 0 : Comparator hysteresis select bits
0<<12 | // HYSSEL 1 : Comparator hysteresis select bits
0<<13 | // CMPSIDL : Stop in iddle mode bit
0<<14 | // Unimplemented
0<<15; // CMPON : Comparator Operating Mode bit
//CMPCON1 = iConfigCMPCON1;
//CMPCON2 = iConfigCMPCON2;
CMPCON1 = 0x8585;
CMPCON2 = 0x0485;
//
//// Ports I/O
set_tris_a(iConfigPortA);
set_tris_b(iConfigPortB);
//
//// Configuration des résistances tirées au GND
output_low(PIN_A2);
output_low(PIN_A3);
output_low(PIN_A4);
output_low(PIN_B2);
output_low(PIN_B4);
output_low(PIN_B8);
output_low(PIN_B9);
output_low(PIN_B10);
output_low(PIN_B11);
output_low(PIN_B12);
output_low(PIN_B13);
output_low(PIN_B14);
//
//// Initialisation des divers signaux
output_low(LED_BLINK);
output_low(TRIGGER_ENABLE);
output_low(POWER_ENABLE);
//
//// Initialisation variables
bStateBlinkingLed = 0;
tick_counter_blink_led = 0;
SerialCommand = 0;
SerialHArg = 0;
SerialLArg = 0;
NouvelleCommandeRS232 = 0;
//
//// Timer 1 (Led clignotante)
set_timer1(TIMER1_VALUE);
setup_timer1(TMR_INTERNAL);
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
//
//// Timer 2 (Timout reception RS232)
setup_timer2(TMR_INTERNAL);
clear_interrupt(INT_TIMER2);
enable_interrupts(INT_TIMER2);
//
//// Enable global interrupts
enable_interrupts(INTR_GLOBAL);
//
//// Boucle de fonctionnement
do
{
// Gestion Led clignotante
if(bStateBlinkingLed)
{
output_high(LED_BLINK);
}
else
{
output_low(LED_BLINK);
}
// Gestion commandes RS232
/*if(NouvelleCommandeRS232)
{
switch(SerialCommand)
{
// Définition du mode de fonctionnement
case 0x00:
if(SerialLArg == 0x01)
{
// Mode Flash
output_high(TRIGGER_ENABLE);
printf("%x%x",0x00, 0x00);
}
else if(SerialLArg == 0x02)
{
// Mode Eclairage
output_low(TRIGGER_ENABLE);
printf("%x%x",0x00, 0x00);
}
else
{
printf("%x%x",0x00, 0x01);
}
break;
// Enable Light (mode Eclairage)
case 0x01:
if(SerialLArg == 0x01)
{
output_high(POWER_ENABLE);
printf("%x%x",0x01, 0x00);
}
else if(SerialLArg == 0x02)
{
output_low(POWER_ENABLE);
printf("%x%x",0x01, 0x00);
}
else
{
printf("%x%x",0x01, 0x01);
}
break;
// Réglage puissance éclairage
case 0x02:
PuissanceEclairage = (SerialHArg << 8) + SerialLArg;
CMPDAC1 = PuissanceEclairage & 0x03FF;
printf("%x%x",0x02, 0x00);
break;
// Unknown command
default:
printf("%x%x",0xFF, 0x01);
break;
}
NouvelleCommandeRS232 = 0;
}*/
//
//// Tests
output_low(TRIGGER_ENABLE);
output_high(POWER_ENABLE);
CMPDAC1 = 500;
}
while (TRUE);
} |
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Wed Dec 18, 2013 12:54 pm |
|
|
Almost. You want #word not #byte. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Wed Dec 18, 2013 3:13 pm |
|
|
real close !!
you have ...
#BYTE CMPCON1 = 0x0540
...which means that 'CMPCON1' is 8 bits long( a byte) located at 0x540
you really need
#WORD CMPCON1 = 0x0540
...which means that 'CMPCON1' is 16 bits long( a word) located at 0x540
hth
jay |
|
|
Fabrici
Joined: 11 Feb 2013 Posts: 19 Location: Toulouse - France
|
|
Posted: Thu Dec 19, 2013 4:01 am |
|
|
A big thanks for the help.
It works perfectly now (at least for this part ^^).
Have a nice day. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Dec 19, 2013 9:15 am |
|
|
As a comment, there is also a way of doing larger things.
#BYTE can be used two different ways.
By default it creates a 'byte' sized variable at a location. #WORD creates a 16bit variable at a location.
However you can also use it like this:
Code: |
int32 val;
#BYTE val=0x1234
|
Done like this, #BYTE _locates_ the already defined variable at the specified memory address. This allows you to define things like fp values, or even arrays at a particular location in RAM.
Can be useful sometimes.
Best Wishes |
|
|
|
|
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
|