CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problems call the function with dspic

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Danilo3012



Joined: 19 May 2011
Posts: 2
Location: Brasil

View user's profile Send private message

problems call the function with dspic
PostPosted: Thu May 19, 2011 6:22 pm     Reply with quote

i have problems with this code
Code:

#include <main.h>
#include <lcd4.c>
#use i2c(Master,Fast,sda=PIN_G2,scl=PIN_G3,force_hw)
int sds;
#int_TIMER2
void  TIMER2_isr(void)
{

}

#int_TIMER4
void  TIMER4_isr(void)
{

}

#int_ADC1
void  ADC1_isr(void)
{

}
void teste()
{
}
void main()
{
   setup_adc_ports(sAN1);
   setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);

   setup_timer2(TMR_INTERNAL |TMR_DIV_BY_1 |TMR_32_BIT , 0);
   setup_timer4(TMR_INTERNAL |TMR_DIV_BY_1 |TMR_32_BIT , 0);
   setup_timer6(TMR_DISABLED |TMR_DIV_BY_1 ,0);
   setup_timer8(TMR_DISABLED |TMR_DIV_BY_1 ,0);
   setup_timer7(TMR_DISABLED |TMR_DIV_BY_1 ,0);
   setup_timer9(TMR_DISABLED |TMR_DIV_BY_1 ,0);

   setup_wdt(WDT_OFF);
   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_ADC1);
//   ini_lcd();

  while(true)
   {
   }
   // TODO: USER CODE!!

}

Code:


#define lcd_db7 pin_g15 // pino de dados d7 do LCD
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Definição e inicialização dos port's *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//#use fast_io(a) // Inicialização rápida dos Pinos de I/O
//#use fast_io(b)
//#use fast_io(c)
//#use fast_io(d)
//#use fast_io(e)
//#byte porta = 0x05
//#byte portb = 0x06
//#byte portc = 0x07
//#byte portd = 0x08
//#byte porte = 0x09
/***************************************************************************/
/* Rotinas para o LCD */
/***************************************************************************/
//Este é o bloco com as rotinas necessárias para manipular o LCD
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Envio de "Nibble" para o LCD *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//Esta rotina lê o "Nibble" inferior de uma variável e envia para o LCD.
void envia_nibble_lcd(int dado)
{
//Carrega as vias de dados (pinos) do LCD de acordo com o nibble lido
output_bit(lcd_db4, bit_test(dado,0)); //Carrega DB4 do LCD com o bit DADO<0>
output_bit(lcd_db5, bit_test(dado,1)); //Carrega DB5 do LCD com o bit DADO<1>
output_bit(lcd_db6, bit_test(dado,2)); //Carrega DB6 do LCD com o bit DADO<2>
output_bit(lcd_db7, bit_test(dado,3)); //Carrega DB7 do LCD com o bit DADO<3>
//Gera um pulso de enable
output_high(lcd_enable); // ENABLE = 1
delay_us(1); // Recomendado para estabilizar o LCD
output_low(lcd_enable); // ENABLE = 0
return; // Retorna ao ponto de chamada da função
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Envio de Byte para o LCD *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//Esta rotina irá enviar um dado ou um comando para o LCD conforme abaixo:
// ENDEREÇO = 0 -> a variável DADO será uma instrução
// ENDEREÇO = 1 -> a variável DADO será um caractere
void byte_lcd(boolean endereco, int dado)
{
output_bit(lcd_rs,endereco); // Seta o bit RS para instrução ou caractere
delay_us(100); // Aguarda 100 us para estabilizar o pino do LCD
output_low(lcd_enable); // Desativa a linha ENABLE
envia_nibble_lcd(dado>>4); // Envia a parte ALTA do dado/coamndo
envia_nibble_lcd(dado & 0x0f);// Limpa a parte ALTA e envia a parte BAIXA do
// dado/comando
delay_us(40); // Aguarda 40us para estabilizar o LCD
return; // Retorna ao ponto de chamada da função
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Envio de caractere para o LCD *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Esta rotina serve apenas como uma forma mais fácil de escrever um caractere
// no display. Ela pode ser eliminada e ao invés dela usaremos diretamente a
// função envia_byte_lcd(1,"<caractere a ser mostrado no lcd>"); ou
// envia_byte_lcd(1,<código do caractere a ser mostrado no lcd>);
void w_lcd(char c)
// envia caractere para o display
{
byte_lcd(1,c);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Função para limpar o LCD *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Como esta operação pode ser muito utilizada, transformando-a em função
// faz cvom que o código compilado seja menor.
void limpa_lcd()
{
byte_lcd(0,0x01); // Envia instrução para limpar o LCD
delay_us(2000); // Aguarda 2ms para estabilizar o LCD
return; // Retorna ao ponto de chamada da função
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Inicializa o LCD *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void ini_lcd()
{
output_low(lcd_db4); // Garante que o pino DB4 estão em 0 (low)
output_low(lcd_db5); // Garante que o pino DB5 estão em 0 (low)
output_low(lcd_db6); // Garante que o pino DB6 estão em 0 (low)
output_low(lcd_db7); // Garante que o pino DB7 estão em 0 (low)
output_low(lcd_rs); // Garante que o pino RS estão em 0 (low)
output_low(lcd_enable);// Garante que o pino ENABLE estão em 0 (low)
delay_us(5000); // Aguarda 15ms para estabilizar o LCD
delay_us(5000);
delay_us(5000);
envia_nibble_lcd(0x03);// Envia comando para inicializar o display
delay_us(5000); // Aguarda 5ms para estabilizar o LCD
envia_nibble_lcd(0x03);// Envia comando para inicializar o display
delay_us(5000); // Aguarda 5ms para estabilizar o LCD
envia_nibble_lcd(0x03);// Envia comando para inicializar o display
delay_us(5000); // Aguarda 5ms para estabilizar o LCD
envia_nibble_lcd(0x02);// CURSOR HOME - Envia comando para zerar o contador de
// caracteres e retornar à posição inicial (0x80).
delay_us(1000); // Aguarda 1ms para estabilizar o LCD
byte_lcd(0,0x28);// FUNCTION SET - Configura o LCD para 4 bits,
// 2 linhas, fonte 5X7.
byte_lcd(0,0x0c);// DISPLAY CONTROL - Display ligado, sem cursor
limpa_lcd(); // Limpa o LCD
byte_lcd(0,0x06);// ENTRY MODE SET - Desloca o cursor para a direita
//return; // Retorna ao ponto de chamada da função
}

Code:


#include <33FJ64GP706.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWRTB                   //Boot block not write protected
//#FUSES BSSH1792             
#FUSES RBS1024                  //Boot RAM is 1024 bytes
#FUSES NOWRTSS                  //Secure segment not write protected
#FUSES SSSH32K               
#FUSES NORSS                    //No secure segment RAM
#FUSES NOWRTSS                  //Secure segment not write protected
#FUSES NOPROTECT                //Code not protected from reading
#FUSES SOSC                 
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES PUT128                   //Power On Reset Timer value 128ms
//#FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
#FUSES NOJTAG                   //JTAG disabled
#FUSES NODEBUG                  //No Debug mode for ICD

#use delay(clock=20000000)


when I delete the comment line ini_lcd ccs of problems, the version I use is 4114, anyone have any solution I'm going crazy with this. : shock:
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu May 19, 2011 11:26 pm     Reply with quote

- You didn't tell, which problems you observed.
- The definition of some IOs is missing from the code.
- Did you try to run the code without flash protection (#fuse SSSH32K)? It may be incompatible with CCS C operation. With this fuse set, the code even doesn't run in MPLAB simulator.
jeremiah



Joined: 20 Jul 2010
Posts: 1322

View user's profile Send private message

PostPosted: Fri May 20, 2011 7:57 am     Reply with quote

For some reason I thought you had to enable global interrupts after enabling the individual ones. Otherwise they wouldn't fire.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri May 20, 2011 8:50 am     Reply with quote

Quote:
I thought you had to enable global interrupts after enabling the individual ones. Otherwise they wouldn't fire.

That's true, but interrupts are effectively unused in the code, there are only empty ISRs.
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Fri May 20, 2011 9:38 am     Reply with quote

In which case then, the code should not be there....

This is a critical part, of debugging, and of posting code here:

Before posting, the code should be _stripped_ of everything not involved in the problem, and the code should be compilable.
If the code is a 'snippet', it makes it impossible for us to compile it, while if it has 'dross' present, it makes it vastly harder for us to read.

Basically if interrupts are not used, the interrupt handlers should not be present, nor should the interrupt enables.

The act of stripping the code, will often _find the fault_, and if it doesn't, it makes it 100* easier to see what the problem is likely to be. If the code is anything over perhaps about 50 lines, then it is probably too long for most people to look at...

Post should be minimum stripped code. Exact details of compiler version.
Exact details of fault.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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