Выкладываю фрагмент проекта.
[/code#include "main.h"
#include ‹LCD.C›
#include ‹math.h›
//-----------------------------
void unsigned int16 HexBDC(unsigned int16 v)
{
hndr=0; tens_once=0;
while (v›99)
{
v=v-0x64; hndr++;
}
while (v›9)
{
v=v-0x0a; tens_once=tens_once+0x10;
}
tens_once=tens_once+v;
}
//-----------------------------
//-----------------------------
#int_TIMER1
void TIMER1_isr(void)
{
T1IF=0;
set_timer1(64779);
if (time_1s==2000)
{
Fl_1s=1;time_1s=0;
}
else
{
time_1s++;
}
if (Fl_measure)
{
SET_ADC_CHANNEL(0);
delay_us(2);
// ADCON0|=2;
while(DONE)
{}
Ia.Nx=read_adc();
delay_us(2);
SET_ADC_CHANNEL(1);
delay_us(2);
// ADCON0|=2;
while(DONE)
{}
Ib.Nx=read_adc();
delay_us(2);
SET_ADC_CHANNEL(2);
delay_us(2);
// ADCON0|=2;
while(DONE)
{}
Ic.Nx=read_adc();
delay_us(2);
}
}
//-------------------------------------------
void main()
{
setup_adc_ports(sAN0|sAN1|sAN2|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
setup_spi(SPI_SS_DISABLED);
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_

;
setup_vref(FALSE);
enable_interrupts(INT_TIMER1 | INTR_LEVEL1);
T1IE=1;
SET_TRIS_B(1);SET_TRIS_A(3);SET_TRIS_C(0);
PR1=60536;
//------------------
lcd_init();
Ua.No=Ub.No=Uc.No=10;
Ia.No=Ib.No=Ic.No=512;
lcd_gotoxy( 1, 1);
set_timer1(64779);
enable_interrupts(INTR_GLOBAL);
Flags=0;time_1s=0;
while (1)
{
while (!Fl_1s)
{
}
Fl_1s=0;
Fl_measure=1;
while (!Meas_done)
{
}
Fl_measure=0;
}
}
//---------------------------------------
]
[/code#include ‹24FJ64GA004.h›
#device *=16
#device adc=10
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
//#FUSES ICS3 //ICD communication channel 3
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO //Internal External Switch Over mode enabled
#FUSES FRC_PLL //Internal Fast RC oscillator with PLL
#FUSES NOSKSFSM //Clock Switching Mode is disabled
#FUSES NOOSCIO //OSC2 is general purpose output
//#FUSES PR_PLL //PR //Pimary oscillaotr disabled
#FUSES I2C1SELD
#use delay(clock=20000000,RESTART_WDT)
struct Flui_map{
boolean beg;
boolean done;
}Fl_Ua,Fl_Ub,Fl_Uc,Fl_Ia,Fl_Ib,Fl_Ic;
struct UI
{
unsigned int32 Nx,X;
unsigned int8 cnt_smpl;
unsigned int8 cnt_beg;
unsigned int8 cnt_cicls;
unsigned int8 cnt_prm0;
unsigned int16 No;
}Ua,Ub,Uc,Ia,Ib,Ic;
unsigned int16 time_1s;
unsigned char Flags;
unsigned char hndr,tens_once;
#bit Meas_done=Flags.0
#bit Fl_measure=Flags.2
#bit Fl_1s=Flags.7
#byte AD1CHS=0x03228
#byte AD1CON1=0x0320
#byte AD1CON2=0x0322
#byte AD1CON3=0x0324
#byte AD1PCFG=0x032c
#byte AD1CSSL=0x0330
#byte ADC1BUF0=0x0300
#byte ADC1BUF1=0x0302
#byte ADC1BUF2=0x0304
#byte PR1=0x102
#byte IEC0=0x094
#byte IFS0=0x084
#bit T1IF=IFS0.3
#bit T1IE=IEC0.3
#bit samp=AD1CON1.1
#bit DONE=AD1CON1.0
#bit adon=AD1CON1.7
]
Среда MPLAB 8.20.
При отладке в симуляторе MPLAB программа работает. При использовании в MPLAB в качестве дебаггера Proteus VSM Viewer программа не входит в главный цикл, регистр OSCCON пустой, а в симуляторе правильно устанавливается (0х1120). В чем ошибка?