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 CCS Technical Support

Transition from PIC16F876 to PIC16F916

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



Joined: 14 Sep 2005
Posts: 12

View user's profile Send private message

Transition from PIC16F876 to PIC16F916
PostPosted: Wed Oct 19, 2005 6:33 am     Reply with quote

Hi,

I´m trying to change PIC form PIC16F876 to PIC16F916, but I have had some trouble. Whell, when I turn on my projetc, it doesn´t work! Confused

I´ve noted the PIC16F916 doesn´t have the LVP fuse. How can this affect my project?

The CCP1 pin changed too. But it just control the LCD contrast, so, the other things should work...

Are there another significatives diferences I didn´t get?

Thanks for any help.
_________________
Paulo Bernardi
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Oct 19, 2005 6:41 am     Reply with quote

It took me about an hour of head scratching trying to get my 18F458 -> 16F914 to run. I refer to the F914 because the F916 that you are using is part of the same "family"

You're fuses should be working just fine. Any errors in your #fuses statement would have been flagged as a compile error. okay, so once your past the fuse problems, there are other things to note.

1. Are you running the internal oscillator?

2. Make sure you ensure that your comparators are OFF.

3. I had a problem trying to get portD to work right. The trick was that TRISE.4 would have to be cleared, or else PORTD would be in parallel port mode, and not I/O mode. (Then again, a 28 pin 16F914 might not have this problem).

Here's an example program in the F914 that does work on the PICDEM-2 board, and it uses the internal oscillator:

Code:

#include <16F914.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT, PUT, INTRC_IO
#use delay(clock=8000000) /* one instruction=1us? */
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use I2C(master, SCL=PIN_C3, SDA=PIN_C4)

#byte PIC_OSCCON=0x8F

void main(void)

{
            int data;
            int ack;
            long int fahr;
    unsigned int iteration;

    PIC_OSCCON = 0x7F;
    delay_ms(25);
   
    iteration = 0;

    printf ("\r\n\r\n\r\n");
    while (1)

    {     
        i2c_start();
        ack = i2c_write(0x9A);
        ack = i2c_write(0x00);

        /* send start again */
        i2c_start();
        ack = i2c_write(0x9b);
        data = i2c_read(0);
        i2c_stop();

        // Convert the A/D value to fahrenheit
        fahr = (9 * (long)data);
        fahr = fahr/5;
        fahr = fahr + 32;
        printf ("Iteration = %d, Temp: %ld\r\n", iteration, fahr);
        iteration = iteration + 1;       
        delay_ms(200);
    }
}
Pbernardi



Joined: 14 Sep 2005
Posts: 12

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 6:49 am     Reply with quote

Quote:

1. Are you running the internal oscillator?


No, I use an external clock. But It was working fine on 16F876, so, I don´t think it is a problem.

Quote:

2. Make sure you ensure that your comparators are OFF.


I´ll verify it. Thanks.

Another thing, how does the ANSEL reg work?
_________________
Paulo Bernardi
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Oct 19, 2005 8:00 am     Reply with quote

ANSEL? I looked at page 90 of the datasheet's pdf file. It says that ANSEL and CMCON0 should be initialized to configure digital i/o.

ANSEL = Analog Select Register
CMCON0 has to do with the comparator stuff.

Anyways, to get my 914 to work, i had to issue the following statement while initializing my ports:

Code:

setup_comparator(NC_NC_NC_NC);


This i think turns off the comparator.
Pbernardi



Joined: 14 Sep 2005
Posts: 12

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 10:43 am     Reply with quote

Thanks, Mike, but it didn´t work! Crying or Very sad

It looks like the pic didn´t run, I put a BEEP on first line, but nothing happens.

Any idea?
_________________
Paulo Bernardi
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Oct 19, 2005 5:19 pm     Reply with quote

I don't know what you should do next. For all we know, it might be that your hardware isn't working, who knows.

I wish I had a pic16f916 to try on the picdem, but i don't.

Whenever i'm faced with a new PIC to work with, the first thing I do is get the DIP version of it, slap it onto my PICDEM-2 demo board, and attempt a simple printf("Hello World\r\n"); program to Hyperterminal.

This will ensure me that my #fuses statement is correct, my clock setting is correct, etc. Once i get my printf working, then the rest of it is application-specific.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 5:44 pm     Reply with quote

Quote:
It looks like the pic didn´t run, I put a BEEP on first line, but nothing happens.

Post your little program that beeps. Make sure you post the
#include, #fuses, and #use statements.

Also post your compiler version. This is a number such as 3.191,
or 3.236, and can be found at the top of the .LST file, which is in
your project directory.
Pbernardi



Joined: 14 Sep 2005
Posts: 12

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 4:19 am     Reply with quote

Ok, here is the start of .h file

Code:
 #include <16F916.h>

#use delay(clock=16000000)
#fuses HS, NOWDT, PROTECT, MCLR, BROWNOUT, NOFCMEN, NOIESO, PUT

#define LIMPA 0x01
#define RETORNO 0x02

// Organização de memória EEPROM (EEPROM memory organization)

#define   M_Pre          0
#define M_p2         1
#define M_p3         2
#define M_p2_220      3   //2 bytes
#define M_p2_127      5   //2 bytes
#define M_p3_220      7   //2 bytes
#define M_p3_127      9   //2 bytes
#define M_f1         11
#define M_CCPR1L      12
#define M_n_disparos   13  //2 bytes
#define M_inicio_tab   15   //2 bytes

// Definição dos bits de habilitação dos displays (displays enable bits)
#bit En    = 0x07.3
#bit Rs    = 0x07.4

//  Definição das teclas (keys definitions)
#bit K1 = 0x05.3
#bit K2 = 0x05.4
#bit C0 = 0x06.0
#bit C1 = 0x06.1
#bit C2 = 0x06.2
#bit C3 = 0x06.3
#bit C4 = 0x06.4
#bit C5 = 0x06.5

// Beep
#bit BEEP = 0x05.5

// Definição dos dados do display (display data)
#byte DADOS = 0x06 // PORTB
#byte DIR_DADOS= 0x86 //TRISB

// Acionamento dos leds (LEDs)
#bit LED1 = 0x07.0
#bit LED2 = 0x07.1

#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07

// Acionamento dos reles
#bit RL1 = 0x07.5
#bit RL2 = 0x07.6
#bit RL3 = 0x07.7

// Verificação dos reles
#bit ON1 = 0x05.1
#bit ON2 = 0x05.2

// Registros de direção
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87

// Bytes de configuração
#byte adcon1 = 0x9F
#byte adcon0 = 0x1F
#byte adresh = 0x1E
#byte adresl = 0x9E

// Bytes de configuração
#byte OPTION = 0x81
#byte INTCON = 0x0B
#byte PIE1   = 0x8C
#byte PIR1   = 0x0C
#bit  TMR1IF = PIR1.0

//Timer 1
#byte TMR1L = 0x0E
#byte TMR1H = 0x0F
#byte T1CON = 0x10

#bit TMR1ON = T1CON.0

// Configuração do PWM
#byte TMR2 = 0x11
#byte PR2 = 0x92
#byte T2CON = 0x12
#byte CCPR1L = 0x15
#byte CCPR1H = 0x16
#byte CCP1CON = 0x17

//configuração de bits de seleção analógica
#byte ANSEL = 0x91

//Configuração do oscilador
#byte OSCCON = 0x8F

// Definição dos bits de configuração
#bit go_done = adcon0.2  //Conversão em progresso


The file .h is included. The start of main() and config() are:

Code:


void main()
{
   BEEP = 1;
   
   config();
     
                (...)
}

void config()
{
   //zera variáveis
   l12=&leds;
   status.kbhit = 0;
   l12[0] = 0;
   l12[1] = 0;
   leds.j = 1;
   leds.e = 1;
   leds.rx1 = 1;
   status.dig = 0;
   status.aut = 0;
   debounce.w = 0;
   digital = 0;
   ponteiro = inicio_tabela;
   exposicao = valores[ponteiro];

   OSCCON = 0x0E;

   OPTION = 0x00;
   
   // Configuração dos ports
   TRISA = 0x07;
   TRISB = 0x00;
   TRISC = 0x00;
   
   // Conversor AD
   adcon1 = 0x8E;
   adcon0 = 0x81;
   
   // Configuração do timer
   T1CON = 0x01;   // Timer1, no pre, clk int.
   INTCON = 0xC0;   // Habilita máscara
   PIE1 = 0x01;   // Habilita interrupção do timer1
   TMR1H = (65535-4000)/256;   // Base de tempo de 1ms
   TMR1L = 95;

   // zera comparadores
   setup_comparator(NC_NC_NC_NC);
   
   // Configuração do PWM
   //PR2 = 0xFF;
   //T2CON = 0x04;
   //CCPR1L = 0x10;
   //CCP1CON = 0x0F;
   
   // Inicialização das portas analógicas
   ANSEL = 0;

   // Inicialização de variáveis
   LED1 = 1;
   LED2 = 0;
   BEEP = 0;
   RL1 = 0;
   RL2 = 0;
   RL3 = 0;
   debouncing = 0;
   K1 = 1;
   K2 = 1;
   
   
   // Recupera valores da EEPROM
   pre = r_eeprom(m_pre);
   p2   = r_eeprom(M_p2);
   p3  = r_eeprom(M_p3);
   rec.b.l = r_eeprom(M_p2_220);
   rec.b.h = r_eeprom(M_p2_220 + 1);
   p2_220= rec.w;
   rec.b.l = r_eeprom(M_p2_127);
   rec.b.h = r_eeprom(M_p2_127 + 1);
   p2_127= rec.w;
   rec.b.l = r_eeprom(M_p3_220);
   rec.b.h = r_eeprom(M_p3_220 + 1);
   p3_220= rec.w;
   rec.b.l = r_eeprom(M_p3_127);
   rec.b.h = r_eeprom(M_p3_127 + 1);
   p3_127= rec.w;
   fl.b = r_eeprom(M_f1);
   CCPR1L = r_eeprom(M_CCPR1L);
   if(CCPR1L == 0xFF)
   {
      CCPR1L = 0;
      wr_eeprom(12, CCPR1L);
   }
   rec.b.l = r_eeprom(M_n_disparos);
   rec.b.h = r_eeprom(M_n_disparos + 1);
   n_disparos= rec.w;

   inicio_tabela = r_eeprom(M_inicio_tab);   // recupera o vetor de inicio da tabela
   if (inicio_tabela && inicio_tabela != 7)   // Se não for 0 ou 7, zera
      inicio_tabela = 0;
   
   timer_10ms = 10;
   while(timer_10ms);
      
   v1_220 = (float)(p2_220 - p3_220)/32;
   v1_127 = (float)(p2_127 - p3_127)/39;
   
   //Inicialização do display
   config_disp();
}


The CCS version is 3.324. This code run on PIC16F876 (without the setup_comparators and ANSEL configuration and with teh CCP configuration, with is used to change the LCD contrast)

The commentary are in portuguese.
_________________
Paulo Bernardi
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

PostPosted: Sat Oct 22, 2005 10:45 am     Reply with quote

One of the first things I had to do with the 16F913, was to disable the LCD module, as it prevented ports C0, C1 and C2 from working.
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