AlbertHall
- Joined Jun 4, 2014
- 12,625
And in fact will lock up the program if there is no interrupt handler for them.THERE IS NO NEED TO SET RCIE or TXIE!!!!!!!!!!!! How many times to I need to mention that?
And in fact will lock up the program if there is no interrupt handler for them.THERE IS NO NEED TO SET RCIE or TXIE!!!!!!!!!!!! How many times to I need to mention that?
Ok. Can someone tell me how to be able to set SYNC to right value??
No more clues??If the data sheet says to clear the sync bit for async mode then I guess you need to clear the sync bit for async mode.![]()
Whatever its default value, your program will be more reliable if you set all the values which you rely on.yes , how? , unless it's standard cleared , but cant see any default value
yes , how? , unless it's standard cleared , but cant see any default value
Sorry, i have not your edducation in electronics, but i can so much other thing,
If it was easy, i would have done it,
Now i ran in to trouble and asked for help.
Data sheet have been read several times, but maybe it's cause i dont know all the terms and so,
I know i have done my best, and tried several things,
I have a working setup for a couple years ago, with 2 ps 16F1509 by serial comm, and that works,
Have been studing those files, and think i have done it correct.
//
#include "lcd.c"
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#pragma config FEXTOSC = LP //XT // External Oscillator mode selection bits (XT (crystal oscillator) above 500kHz, below 4MHz; PFM set to medium power)
#pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = OFF // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
#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)
#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)
#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.)
#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)
#define _XTAL_FREQ 16000000
#define FOSC 4000000L
#define back_light RB0
#define led1_on RE0
#define KN1 RC3
#define KN2 RC2
#define KN3 RA7
#define KN4 RA6
#define Skip_ROM 0xCC
#define Convert_T 0x44
#define Read_scratchpad 0xBE
#define Port_18B20 RB5
#define Tx_18B20 TRISB5 = 0
#define Rx_18B20 TRISB5 = 1
#define WAIT1 1000
#define WAIT2 500
#define DS18B20_CONV_TIME 750
#define DS18B20_RESET_PULSE 480
#define DS18B20_WAIT_TIME 60
#define DS18B20_PULLUP_TIME 2
#define ONEWIRE_PRESENT 0
#define ONEWIRE_ABSENT 1
bit modtaget,data_tick,sekund;
int get_value,data_inde,Data_Buffer,run;
unsigned char printchar[10];
// Functions Declarations
void UART_RX_Init(void);
// Globals
uint8_t UART_Buffer = 0; // is a 8bit interger / 1.byte
//--------------------------------
static void interrupt isr(void) // Here is interrupt function - the name is unimportant.
{
if(TMR1IF) // Was this a timer overflow?
{
TMR1IF=0; // Clear interrupt flag, ready for next // timer run to 65k, gives 2 sec interrupt
//TMR1L=0x00; // overflow every 2 seconds. to prevent to much interrupt.
//TMR1H=0x80; // If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
sekund=1;
}
if (RCIF==1)
{
CREN=0;
run=0;
lcd_clear();
lcd_puts("Modtaget");
while(RCIF==1)
{
UART_Buffer = RCREG; // Read The Received Data Buffer
run++;
}
// This could have been done within the main loop. Since it's not
// Excessive processing, so it's OK to do it here below
if(UART_Buffer-48 == 0x00)
lcd_puts("Davs");
if(UART_Buffer-48 == 0x01)
lcd_puts("Farvel");
//RCIF = 0; // Clear The Interrupt Flag read only
lcd_goto(0x40); // goto line2
utoa(printchar,UART_Buffer-48,10);
lcd_puts(printchar);
utoa(printchar,run,10);
lcd_goto(0x54);
lcd_puts(printchar);
CREN=1;
}
}
void setup(void)
{
COSC0=0;
COSC1=0;
COSC2=1; // use second oss.
HFFRQ0=1;
HFFRQ1=0;
HFFRQ2=1; // 16 mhz
TRISA0=1; // NU
TRISA1=1; // NU
TRISA2=1; // NU
TRISA3=1; // NU
TRISA4=1; // input to timer
TRISA5=1; // NU
TRISA6=1; // Button 1
TRISA7=1; // Button 2
TRISB0=0; // Backlight on/off
TRISB1=0; // not used
TRISB2=0; // not used
TRISB3=0; // RS
TRISB4=0; // not used
TRISB5=1;// CHANGE temp reading DS18B20
TRISB6=1; // program
TRISB7=1; // program
TRISC0=1; // Xtal
TRISC1=1; // Xtal.
TRISC2=1; // button 3
TRISC3=1; // button 4
TRISC4=1; // not used
TRISC5=1; // not used
//TRISC6=0; //send data
//TRISC7=1; // recieve data
TRISD0=0; // DATA6
TRISD1=0; // DATA7
TRISD2=0; // DATA5
TRISD3=0; // DATA4
TRISD4=0; // NU
TRISD5=0; // NU
TRISD6=0; // NU
TRISD7=0; // ENABLE LCD
TRISE0=0; // LED Out
TRISE1=1; // NU
TRISE2=1; //NU
ANSELA=0b00000000; // set alle digital.
ANSELB=0b00000000;
ANSELC=0b00000000;
ANSELD=0b00000000;
ANSELE=0b0000;
//RXPPS=RC6;
//TXPPS=RC7;
//timer 1 setup
T1CS0=0; // 0110 = SOCS
T1CS1=1;
T1CS2=1;
T1CS3=0;
T1CKPS0=0; // no prescale
T1CKPS1=0;
nT1SYNC=1; // no sync
lcd_init(); //lcd's init
lcd_goto(0);
}
void UART_RX_Init()
{
BRGH = 1; // Set For High-Speed Baud Rate
SPBRG = 103; // Set The Baud Rate To Be 9600 bps
// Enable The Ascynchronous Serial Port
TX1STAbits.SYNC = 0;
SPEN = 1;
// Set The RX-TX Pins to be in UART mode (not io)
TRISC6 = 1; // As stated in the datasheet
TRISC7 = 1; // As stated in the datasheet
//--[ Enable UART Receiving Interrupts ]--
RCIE = 1; // UART Receving Interrupt Enable Bit
PEIE = 1; // Peripherals Interrupt Enable Bit
GIE = 1; // Global Interrupt Enable Bit
//------------------
RX9=0; // not 9 bit
TX9=0;
CREN = 1; // Enable Data Continous Reception
TXEN=1; // enables transmitter
}
void UART_Write(uint8_t data)
{
while(!TRMT); // if send buffer is full, then clear the bit
TXREG = data; // moves data to send reg,
}
void main (void)
{
setup();
UART_RX_Init(); // Initialize The UART in Master Mode @ 9600bps
lcd_clear();
lcd_goto(0x00);
back_light=1; // turn on light in LCD
lcd_puts("Line 1 : Hello");
lcd_goto(0x40);
lcd_puts("Line 2 : Denmark!");
lcd_goto(0x14);
lcd_puts("Line 3 : World");
lcd_goto(0x54);
lcd_puts("Line 4 : Goodbye!");
RE0=1; // little led on, indicates 2 sec gab
T1RD16=0; // turn on timer1 16 bit read write
TMR1ON=1; // turn on timer1
T1GE=0; // gate allways count
TMR1IE=1; // enable interrupr for timer1
GIE=1; // enable global interrupr
PEIE=1; // enable interrupr
__delay_ms(500); // delay
while (1)
{
if (sekund==1)
{ sekund=0;
(led1_on=!led1_on);
}
if (!KN1) // for test only
{
TXEN=1; // enables transmitter
lcd_clear();
UART_Write(0b00011001); // should send something to BT, ex 25
}
if (!KN2) // not used yet
{
}
if (data_tick==1) // not used yet
{
data_tick=0;
}
}
}
When you type a number, for example '0' the computer records the ascii/ansii code for that character which is decimal 48.Don't really know why it adds 48 to my number i send from terminal,
When you type a number, for example '0' the computer records the ascii/ansii code for that character which is decimal 48.
http://www.asciitable.com/
The problem is still that i cant send anything from microchip
#include <xc.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma config FEXTOSC = LP //XT // External Oscillator mode selection bits (XT (crystal oscillator) above 500kHz, below 4MHz; PFM set to medium power)
#pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = OFF // Clock Switch Enable bit (The NOSC and NDIV bits cannot be changed by user software)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
#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)
#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)
#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.)
#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)
#define _XTAL_FREQ 4000000
#define FOSC 1000000L
void UART_RX_Init()
{
ANSELB=0;
ANSELC=0;
BRGH = 1; // Set For High-Speed Baud Rate
SPBRG = 103;//25; // Set The Baud Rate To Be 9600 bps
// Enable The Ascynchronous Serial Port
TX1STAbits.SYNC = 0;
SPEN = 1;
// Set The RX-TX Pins to be in UART mode (not io)
TRISC6 = 1; // As stated in the datasheet
TRISC7 = 1; // As stated in the datasheet
//--[ Enable UART Receiving Interrupts ]--
// RCIE = 1; // UART Receving Interrupt Enable Bit
// PEIE = 1; // Peripherals Interrupt Enable Bit
// GIE = 1; // Global Interrupt Enable Bit
//------------------
TX9=0;
RX9=0;
CREN = 1; // Enable Data Continous Reception
TXEN=1; // enable tranmission
}
void main(void)
{
//--[ Peripherals & IO Configurations ]--
UART_RX_Init(); // Initialize The UART in Master Mode @ 9600bps
while(1)
{
TXREG=0b00000011; // number 3 in binary
TXREG=13; // write CR to activate send
__delay_ms(500);
TXREG=0x02; // write 2 in hex
TXREG=13;
__delay_ms(500);
TXREG=1;//write 1 in decimal
TXREG=13;
__delay_ms(500);
}
}