Página 1 de 1

Oque há de errado com esse código?18f452 CCS

MensagemEnviado: 22 Abr 2009 13:51
por Rubens_Caetano
Olá pessoal, estou iniciando com o PIC18f452 no compilador CCS mesmo por enquanto, esse código funciona no PIC 16F877A com pequenas mudanças, gostaria de saber dos colegas oque há de errado ou oque falta nesse código abaixo:

#include <18f452.h> // microcontrolador utilizado

#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT,BROWNOUT // configuração dos fusíveis

#use delay(clock=10000000, RESTART_WDT)

#use fast_io(a)
#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


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SAÍDAS *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#bit pinoB7 = portb.7

void main()
{
setup_counters(rtcc_internal,rtcc_8_BIT);
// configura os tris
set_tris_a(0b00000000);
set_tris_b(0b00000000);
set_tris_c(0b00000000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);

// inicializa os ports
porta=0x00; // limpa porta
portb=0x00; // limpa portb
portc=0x00; // limpa portc
portd=0x00; // limpa portd
porte=0x00; // limpa porte

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Loop principal *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

while(TRUE) // rotina principal
{
pinoB7 = 1 ;
delay_ms(10);
pinoB7 = 0;
delay_ms(10);
}
}

MensagemEnviado: 22 Abr 2009 14:30
por fabim
na série 18F.
PAra escrever no pino é LATA, LATB....
Para ler o pino é PORTA, PORTB...
Para configurar com I/O , TRISA, TRISB....

Coisas de datasheet...

fabim

Código que funfa :

MensagemEnviado: 22 Abr 2009 16:17
por Rubens_Caetano
Segui seu conselho Fabim e olhei melhor o datashit, os endereços dos PORTA,PORTB ... estavam errados segue abaixo o código corrigido :

#include <18f452.h> // microcontrolador utilizado

#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT,BROWNOUT // configuração dos fusíveis

#use delay(clock=10000000, RESTART_WDT)

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)

#byte porta = 0xf80
#byte portb = 0xf81
#byte portc = 0xf82
#byte portd = 0xf83
#byte porte = 0xf84


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SAÍDAS *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#bit pinoB7 = PORTB.7

void main()
{
setup_counters(rtcc_internal,rtcc_8_BIT);
// configura os tris
set_tris_a(0b00000000);
set_tris_b(0b00000000);
set_tris_c(0b00000000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);

// inicializa os ports
porta=0x00; // limpa porta
portb=0x00; // limpa portb
portc=0x00; // limpa portc
portd=0x00; // limpa portd
porte=0x00; // limpa porte

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Loop principal *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

while(TRUE) // rotina principal
{
pinoB7 = 1 ;
delay_ms(10);
pinoB7 = 0;
delay_ms(10);
}
}

Obrigado pela atenção !!!
Abraço !!!

MensagemEnviado: 22 Abr 2009 19:17
por fabim
ta errado boy..
E se uC for ler um pino do port ?
Vai ler o valor setado para o laT, e não o valor real do port...

Cunserta essa coisa aí..

LAT is LAT and PORT IS PORT..

IF write then LAT.
IF read then PORT.

fabim

Corrigindo ...

MensagemEnviado: 23 Abr 2009 09:02
por Rubens_Caetano
Corrigindo ...
Eu havia postado o código acima pq tinha funfado ... porem a saída não está configurada certa como nosso colega observou.Agora estou postando novamente o código corrigido:

#include <18f452.h> // microcontrolador utilizado

#fuses HS,NOWDT,PUT,NOLVP,NOPROTECT,BROWNOUT // configuração dos fusíveis

#use delay(clock=10000000, RESTART_WDT)

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)


#byte porta = 0xf80
#byte portb = 0xf81
#byte portc = 0xf82
#byte portd = 0xf83
#byte porte = 0xf84


#byte LATA = 0xf89
#byte LATB = 0xf8A
#byte LATC = 0xf8B
#byte LATD = 0xf8C
#byte LATE = 0xf8D

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SAÍDAS *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#bit pinoB7 = LATB.7

void main()
{
setup_counters(rtcc_internal,rtcc_8_BIT);
// configura os tris
set_tris_a(0b00000000);
set_tris_b(0b00000000);
set_tris_c(0b00000000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);

// inicializa os ports
porta=0x00; // limpa porta
portb=0x00; // limpa portb
portc=0x00; // limpa portc
portd=0x00; // limpa portd
porte=0x00; // limpa porte

LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Loop principal *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

while(TRUE) // rotina principal
{
pinoB7 = 1 ;
delay_ms(10);
pinoB7 = 0;
delay_ms(10);
}
}