por carlos_bugs » 06 Mar 2008 21:20
o programa main.c segue abaixo. depois criei um funcoes.c e inclui como arquivo do projeto através do mikroc. porém nesse funcoes.c. essas variáveis declaradas não são visíveis. usei a instrução extern no funcoes.c para especificar uma variável declarada no main.c . essa acao funcionou, mas obriga a declarar sempre quaisquer variavel que se dejeja manipular fora do main.c outra coisa, quando declaro uma struct, o compliador automaticamente mostra os bits criados, pelo assistente de código, porém mesmo declarando através do extern no funcoes.c ele não reconhece. Fabim, não entendi direito quando vc quis dizer fulano=fulano. tentei dentro do main. fazer varx=varx, não adiantou. també tentei usar #include"main.c" dentro do funcoes.c, mas também não funcionou. Vou continuar tentando. Se alguém tiver mai alguma idéia com certeza será de grande valia. agradeço mais uma vez a atenção e ajuda de todos
//------------------------------------------------------------------------------
// VARIÁVEIS GLOBAIS
//------------------------------------------------------------------------------
char txtx[7];
int first_line=0; // DEFINE ROWS OF LCD
int second_line=192;
int third_line=144;
int fourth_line=208;
struct variaveis_botao
{
unsigned int incrementa :1;
unsigned int decrementa :1;
unsigned int enter :1;
unsigned int inc_pressionado :1;
unsigned int dec_pressionado :1;
unsigned int enter_pressionado :1;
unsigned int inc_delay :8;
unsigned int dec_delay :8;
unsigned int enter_delay :8;
} botao;
struct variaveis_menu
{
unsigned int principal :8;
} menu;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// VETOR DE INTERRUPÇÃO
//------------------------------------------------------------------------------
void Timer1Int() org 0x1A
{
IFS0 = IFS0 & 0xFFF7; // Clear TMR1IF
pr1=30000; // base de tempo = 10ms
tempo.aux_10_ms=1;
}
//------------------------------------------------------------------------------
//##############################################
// FUNÇÕES
//##############################################
//------------------------------------------------------------------------------
// base de tempo
//------------------------------------------------------------------------------
void base_tempo()
{
tempo.pulso_10_ms=0;
tempo.pulso_100_ms=0;
tempo.pulso_1s=0;
if(tempo.aux_10_ms) // 10ms
{
tempo.aux_10_ms=0;
tempo.pulso_10_ms=1;
}
if(tempo.pulso_10_ms) // 100ms
{
tempo.aux_100_ms++;
if(tempo.aux_100_ms>9)
{
tempo.aux_100_ms=0;
tempo.pulso_1s=1;
}
}
if(tempo.pulso_10_ms) // 1000ms
{
tempo.aux_1s++;
if(tempo.aux_1s>99)
{
tempo.aux_1s=0;
tempo.pulso_100_ms=1;
}
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// leitura de botoes
//------------------------------------------------------------------------------
void leitura_botoes()
{
if(!tempo.pulso_10_ms) return;
botao.incrementa=0;
botao.decrementa=0;
botao.enter=0;
if(latbbits.LATB0) // botao incrementa
{
if(!botao.inc_pressionado)
{
botao.inc_delay++;
if(botao.inc_delay>15)
{
botao.inc_delay=0;
botao.incrementa=1;
botao.inc_pressionado=1;
}
}
}
else
{
botao.inc_pressionado=0;
botao.inc_delay=0;
}
}
//------------------------------------------------------------------------------
void main() {
//------------------------------------------------------------------------------
// CONFIGURAÇÕES: PROCESSADOR
//------------------------------------------------------------------------------
ADPCFG = 0xFFFF; // PORTB - ALL DIGITALS
TRISBBITS.TRISB0=1; // botao inc
TRISBBITS.TRISB1=1; // botao enter
TRISBBITS.TRISB2=1; // botao dec
TRISBBITS.TRISB3=0; // led1
TRISBBITS.TRISB4=0; // led2
TRISBBITS.TRISB5=0; // led3
TRISBBITS.TRISB9=0; // d7-lcd
TRISBBITS.TRISB10=0; // d6
TRISBBITS.TRISB11=0; // d5
TRISBBITS.TRISB12=0; // d4
TRISFBITS.TRISF0=0; // enable - lcd
TRISFBITS.TRISF1=0; // R/W
TRISFBITS.TRISF4=0; // R/S
OSCCONbits.POST=1; // POSTCALER DO PROCESSADOR =4
IPC0 = IPC0 | 0x1000; // Interrupt priority level = 1
IFS0 = IFS0 & 0xFFF7; // Clear TMR1IF
IEC0 = IEC0 | 0x0008; // Enable Timer1 interrupts
T1CONBITS.TON=1; // enable tmr1
T1CONBITS.TSIDL=0;
T1CONBITS.TSYNC=0;
T1CONBITS.TCS=0;
T1CONBITS.TGATE=0;
T1CONBITS.TCKPS=1; // PRESCALER= 1:8
Lcd_Custom_Config(&PORTB, 9,10,11,12, &PORTF, 4,1,0);
DELAY_MS(100);
LCD_CUSTOM_Cmd(LCD_CURSOR_OFF); // Turn cursor off
//------------------------------------------------------------------------------
latbbits.LATB5=1;
Lcd_CUSTOM_Cmd(Lcd_Clear);
lcd_custom_cmd(first_line);
lcd_custom_out_cp("teste");
lcd_custom_cmd(second_line);
lcd_custom_out_cp("teste2"); // posicao da ddram: linha 2 - coluna 1
lcd_custom_cmd(third_line);
lcd_custom_out_cp("teste3"); // posicao da ddram: linha 3 - coluna 1
lcd_custom_out_cp("teste4");
delay_ms(2500);
//------------------------------------------------------------------------------
// LOOP PRINCIPAL
//------------------------------------------------------------------------------
while(1)
{
base_tempo();
leitura_botoes();
navegacao_menu();
imprime_lcd();
teste();
if(tempo.pulso_10_ms) latbbits.LATB3=~latbbits.LATB3;
if(tempo.pulso_100_ms) latbbits.LATB4=~latbbits.LATB4;
if(tempo.pulso_1s) LATBBITS.LATB5=~LATBBITS.LATB5;
}
//-----------------------------------------------------------------------------
}