#define MINOR_VERSION 0x00
#define MAJOR_VERSION 0x01
#define OUT_CTRLWAIT LATAbits.LATA4
#define OUT_INTZ80 LATAbits.LATA5
#define OUT_SDA LATBbits.LATB0
#define OUT_SDL LATBbits.LATB1
#define OUT_TSTR LATAbits.LATA0
#define OUT_TSTY LATAbits.LATA1
#define OUT_CPU0 LATCbits.LATC0
#define OUT_CPU1 LATCbits.LATC1
#define OUT_CPU2 LATCbits.LATC2
#define OUT_CPU3 LATBbits.LATB3
#define OUT_CPU4 LATBbits.LATB4
#define OUT_CPU5 LATBbits.LATB5
#define OUT_CPU6 LATBbits.LATB6
#define OUT_CPU7 LATBbits.LATB7
#define IN_CPU0 PORTCbits.RC0
#define IN_CPU1 PORTCbits.RC1
#define IN_CPU2 PORTCbits.RC2
#define IN_CPU3 PORTBbits.RB3
#define IN_CPU4 PORTBbits.RB4
#define IN_CPU5 PORTBbits.RB5
#define IN_CPU6 PORTBbits.RB6
#define IN_CPU7 PORTBbits.RB7
#define IN_WR PORTAbits.RA3
#define IN_STATUS_CS2 PORTAbits.RA2
// WR | Result
// 0 | WR Data : Z80 -> PIC
// 1 | RD Data : PIC -> Z80
// Private function prototypes
void isr_int2(void);
void isr_lowpri(void);
void EnviaByte(void);
void RecebeByte(void);
// ADC
void LerADC(int vporta);
// USB
void ComunicarUSB(void);
// SERIAL
void ComunicarSerial(void);
//------------------------------------------------------------
// PROGRAMA PRINCIPAL
//------------------------------------------------------------
void main()
{
// CONFIGURAR PORTAS
OSCCON = 0xFF; // Seta Oscilador Interno para 8 MHz
ADCON1 = 0x0F; // 0x0D => RA0=AN0, RA1=AN1, TODAS AS DEMAIS ANx = DIGITAIS; 0x0F para testes
PORTA = 0x30;
PORTB = 0x00;
PORTC = 0x00;
TRISA = 0x0C; // 0x0F => RA7-X, RA6-X, RA5-INTZ80, RA4-CTRWAIT, RA3-WR, RA2-CS2, RA1-AN1, RA0-AN0; 0x0C para testes
TRISB = 0xFC; // RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
TRISC = 0x97; // RC7-RX, RC6-TX, RC5-D+, RC4-D-, RC3-X, RC2 A RC0 - D2 A D0
RCON = RCON | 0x80;
PIR1 = 0x00;
PIR2 = 0x00;
PIE1 = 0x00;
PIE2 = 0x00;
IPR1 = 0x00;
IPR2 = 0x00;
INTCON = 0xC0; // 0xC0
INTCON2 = 0xE0; // 0xE0
INTCON3 = 0x90; // 0x90
INTCON3bits.INT2IE = 0x00;
INTCON3bits.INT2IF = 0x00;
PIE1bits.RCIE = 0x00;
PIR1bits.RCIF = 0x00;
PIE2bits.USBIE = 0x00;
PIR2bits.USBIF = 0x00;
pbyte = 0x00;
pfunc = 0x00;
plerverif = 0x00;
pbytectrl = 0x00;
OUT_SDA = 0x00;
OUT_SDL = 0x00;
OUT_TSTR = 0x01;
OUT_TSTY = 0x00;
INTCON3bits.INT2IE = 0x01;
...
}
ADCON1 = 0x0F; // 0x0D => RA0=AN0, RA1=AN1, ALL OTHER ANx = DIGITAL's; 0x0F for test
TRISA = 0x0C;
Could it have something to do with the comparator settings?
RA2 is also an analog input to the comparator.
Reg CMCOM
// Configurações do PIC
#pragma config CPUDIV = OSC1_PLL2, USBDIV = 2, PLLDIV = 5 // CONFIG1L
#pragma config FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, VREGEN = ON // CONFIG2L
#pragma config WDT = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = ON // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF // CONFIG5L
#pragma config CPB = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF // CONFIG7L
#pragma config EBTRB = OFF // CONFIG7H
// INTERRUPÇÕES
#define REMAPPED_RESET_VECTOR_ADDRESS 0x0800
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x0808
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x0818
#pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS
void _reset (void)
{
_asm goto 0x0838 _endasm
}
#pragma code high_vector = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS
void high_interrupt (void)
{
_asm GOTO isr_int2 _endasm
}
#pragma code
#pragma code low_vector = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS
void low_interrupt (void)
{
_asm GOTO isr_lowpri _endasm
}
#pragma code
//------------------------------------------------------------
// PROGRAMA PRINCIPAL
//------------------------------------------------------------
void main()
{
// CONFIGURAR PORTAS
ADCON1 = 0x0F;
CMCON = 0x07;
TRISA = 0x14; // RA7-X, RA6-X, RA5-CTRWAIT, RA4-WR, RA3-INTZ80, RA2-CS2, RA1-LEDR, RA0-LEDY
TRISB = 0xFC; // RB7 A RB3 - D7 A D3, RB2-INT2/CS2, RB1-SCL, RB0-SCA
TRISC = 0x97; // RC7-RX, RC6-TX, RC5-D+, RC4-D-, RC3-X, RC2 A RC0 - D2 A D0
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
RCON = RCON | 0x80;
PIR1 = 0x00;
PIR2 = 0x00;
PIE1 = 0x00;
PIE2 = 0x00;
IPR1 = 0x00;
IPR2 = 0x00;
INTCON = 0xC0; // 0xC0
INTCON2 = 0xE0; // 0xE0
INTCON3 = 0x90; // 0x90
INTCON3bits.INT2IE = 0x00;
INTCON3bits.INT2IF = 0x00;
PIE1bits.RCIE = 0x00;
PIR1bits.RCIF = 0x00;
PIE2bits.USBIE = 0x00;
PIR2bits.USBIF = 0x00;
OSCCON = 0xFF; // Seta Oscilador Interno para 8 MHz
INTCON3bits.INT2IE = 0x01;
CVRCON.CVROE = 0;
CVRCONbits.CVROE = 0;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?