Hi
Been struggeling a while.
This code for 16F18877 is making my RB2 allways high, and cant figure it out.
The output is steady, measured with scope, and can easy drive a LED.
Any hint of where the big bug is ?
rgds.
Been struggeling a while.
This code for 16F18877 is making my RB2 allways high, and cant figure it out.
The output is steady, measured with scope, and can easy drive a LED.
Code:
// PIC16F18877 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = EXT1X // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled)
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled)
#pragma config BOREN = ON // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices)
#pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.)
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)
// CONFIG3
#pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT enabled regardless of sleep; SWDTEN ignored)
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)
// CONFIG4
#pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off)
#pragma config SCANE = available// Scanner Enable bit (Scanner module is available for use)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.)
// CONFIG5
#pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled)
#pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdbool.h>
#include <stdint.h>
uint8_t UART_Buffer = 0; // is a 8bit interger / 1.byte
uint8_t data,ID,trash,NightContrastTime,DayContrastTime;
int nytid,contrast,sec,minut,hour,x,i,on_contrast,off_contrast,no90_opens,runs_code90,ReadyToCode90,newsec,newminut,newhour;
int ReadyToCode80,no80_opens,runs_code80,run_first_time,night;
#define _XTAL_FREQ 32000000
void __interrupt() myISR(void)
{// things to do
// only interrupt is from RX EUSART
if (RCIF==1)
{
CREN=0;
UART_Buffer=RCREG;
data=1;
CREN=1;
}
}
void setup_system (void)
{
//setup clock.
OSCCON1=0x60; //OSC Settings
OSCFRQ=0x06; // 32 mhz
PMD0=0x00; // all modules enab.
PMD1=0xff; // all disable, hence not using it.
PMD2=0x67; // all disable, not using
PMD3=0x7F; //all disable
PMD4=0x37; // EUSART module enabled all other disable
PMD5=0xDF; // all disable
LATA=0x00;
LATB=0x00;
LATC=0x00;
LATD=0x00;
LATE=0x00;
TRISA=0xFF; // all input only use 0+3
TRISB=0xD8; // out = B0-B1-B2-B5, IN = B3-B4-B6-B7
TRISC=0x00; // all output
TRISD=0x00; // all output
TRISE=0x07; // all input
ANSELD=0x00; // all digital , no analog function
ANSELC=0x00;
ANSELB=0x00;
ANSELE=0x00;
ANSELA=0x00;
ODCONB=0x00;
ODCONC=0x00;
ODCOND=0x00;
RXPPS=0x0B; // MOVE RX to RB3. RB3 = 0x0B
SSP2DATPPS=0x0C; // try to move it for test, using default RB2. // still no luck
// setup RX system
// ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE disabled; ABDEN disabled;
BAUD1CON = 0x08;
// SPEN enabled; RX9 8-bit; CREN disabled; ADDEN disabled; SREN disabled;
RC1STA = 0x80;
// TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave;
TX1STA = 0x24;
SP1BRGL = 0xBF; //191 aka 10417 baud
// SP1BRGH 0;
SP1BRGH = 0x00;
// next 4 disable for testing right now..
// CREN=1;
// RCIE=1;
// PEIE=1;
//GIE=1;
}
void main(void)
{
setup_system();
data=0;
while(1)
{
__delay_ms(2);
}
}
rgds.