config settings for pic16f1937

Status
Not open for further replies.
Rems... You shouldn't open up these old threads..... start a new one.

ALL the definitions are in the header files...

For example pic16f1937.h in the include directory of Hi-tech shows them all. With comments.

Code:
// Config Register: CONFIG1
#define CONFIG1              0x8007
// Oscillator Selection
// ECH, External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin
#define FOSC_ECH             0xFFFF
// ECM, External Clock, Medium Power Mode (0.5-4 MHz): device clock supplied to CLKIN pin
#define FOSC_ECM             0xFFFE
// ECL, External Clock, Low Power Mode (0-0.5 MHz): device clock supplied to CLKIN pin
#define FOSC_ECL             0xFFFD
// INTOSC oscillator: I/O function on CLKIN pin
#define FOSC_INTOSC          0xFFFC
// EXTRC oscillator: External RC circuit connected to CLKIN pin
#define FOSC_EXTRC           0xFFFB
// HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_HS              0xFFFA
// XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins
#define FOSC_XT              0xFFF9
// LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins
#define FOSC_LP              0xFFF8
// Watchdog Timer Enable
// WDT enabled
#define WDTE_ON              0xFFFF
// WDT enabled while running and disabled in Sleep
#define WDTE_NSLEEP          0xFFF7
// WDT controlled by the SWDTEN bit in the WDTCON register
#define WDTE_SWDTEN          0xFFEF
// WDT disabled
#define WDTE_OFF             0xFFE7
// Power-up Timer Enable
// PWRT disabled
#define PWRTE_OFF            0xFFFF
// PWRT enabled
#define PWRTE_ON             0xFFDF
// MCLR Pin Function Select
// MCLR/VPP pin function is MCLR
#define MCLRE_ON             0xFFFF
// MCLR/VPP pin function is digital input
#define MCLRE_OFF            0xFFBF
// Flash Program Memory Code Protection
// Program memory code protection is disabled
#define CP_OFF               0xFFFF
// Program memory code protection is enabled
#define CP_ON                0xFF7F
// Data Memory Code Protection
// Data memory code protection is disabled
#define CPD_OFF              0xFFFF
// Data memory code protection is enabled
#define CPD_ON               0xFEFF
// Brown-out Reset Enable
// Brown-out Reset enabled
#define BOREN_ON             0xFFFF
// Brown-out Reset enabled while running and disabled in Sleep
#define BOREN_NSLEEP         0xFDFF
// Brown-out Reset controlled by the SBOREN bit in the BORCON register
#define BOREN_SBODEN         0xFBFF
// Brown-out Reset disabled
#define BOREN_OFF            0xF9FF
// Clock Out Enable
// CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
#define CLKOUTEN_OFF         0xFFFF
// CLKOUT function is enabled on the CLKOUT pin
#define CLKOUTEN_ON          0xF7FF
// Internal/External Switchover
// Internal/External Switchover mode is enabled
#define IESO_ON              0xFFFF
// Internal/External Switchover mode is disabled
#define IESO_OFF             0xEFFF
// Fail-Safe Clock Monitor Enable
// Fail-Safe Clock Monitor is enabled
#define FCMEN_ON             0xFFFF
// Fail-Safe Clock Monitor is disabled
#define FCMEN_OFF            0xDFFF


// Config Register: CONFIG2
#define CONFIG2              0x8008
// Flash Memory Self-Write Protection
// Write protection off
#define WRT_OFF              0xFFFF
// 000h to 1FFh write protected, 200h to 1FFFh may be modified by EECON control
#define WRT_BOOT             0xFFFE
// 000h to FFFh write protected, 1000h to 1FFFh may be modified by EECON control
#define WRT_HALF             0xFFFD
// 000h to 1FFFh write protected, no addresses may be modified by EECON control
#define WRT_ALL              0xFFFC
// Voltage Regulator Capacitor Enable
// All VCAP pin functionality is disabled
#define VCAPEN_OFF           0xFFFF
// VCAP functionality is enabled on RA6
#define VCAPEN_RA6           0xFFEF
// VCAP functionality is enabled on RA5
#define VCAPEN_RA5           0xFFDF
// VCAP functionality is enabled on RA0
#define VCAPEN_RA0           0xFFCF
// PLL Enable
// 4x PLL enabled
#define PLLEN_ON             0xFFFF
// 4x PLL disabled
#define PLLEN_OFF            0xFEFF
// Stack Overflow/Underflow Reset Enable
// Stack Overflow or Underflow will cause a Reset
#define STVREN_ON            0xFFFF
// Stack Overflow or Underflow will not cause a Reset
#define STVREN_OFF           0xFDFF
// Brown-out Reset Voltage Selection
// Brown-out Reset Voltage (VBOR) set to 1.9 V
#define BORV_19              0xFFFF
// Brown-out Reset Voltage (VBOR) set to 2.5 V
#define BORV_25              0xFBFF
// Low-Voltage Programming Enable
// Low-voltage programming enabled
#define LVP_ON               0xFFFF
// High-voltage on MCLR/VPP must be used for programming
#define LVP_OFF              0xDFFF
 
please help me to configure serial port in PIC16F1937. iam usinh MPLAB IDE and Hitech complier
here is my program to send ouput string to PIC 2 demo kit.

#include <stdio.h>
#include <stdlib.h>
#include<htc.h>
#use rs232(baud=9600, UART, PARITY=N)

#define BAUD2400_16MHZ 103
#define BAUD2400_4MHZ 25

__CONFIG(0x2F84);
__CONFIG(0x1EFF);
void uart_write(const char *str);
unsigned char uart_read();
char data;



void uart_init(void)
{
TRISC7 = 1;
TRISC6 = 0;
SPBRG = 25; // 4mhz xtal 9600 BAUD
RCSTA = 0x90; // SPEN and CREN
}

void main()
{
uart_init();



uart_write("TestString");


while(1)
{
data = uart_read();

}
}

this is showing error when i build project.here is the error.please help





make[2]: Entering directory `C:/Users/xz4phd/Desktop/PicDem 2 Project/PIC16F/Code/Tempsensor.X'
"C:\Program Files\HI-TECH Software\PICC\9.82\bin\picc.exe" --pass1 serial.c -q --chip=16F1937 -P --outdir=build/default/production -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=lite -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
serial.c:11 warning: illegal # directive "use"
serial.c:11 warning: illegal # directive "use"
"C:\Program Files\HI-TECH Software\PICC\9.82\bin\picc.exe" -odist/default/production/Tempsensor.X.production.cof -mdist/default/production/Tempsensor.X.production.map --summary=default,-psect,-class,+mem,-hex --chip=16F1937 -P --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 -N31 --warn=0 --double=24 --float=24 --addrqual=ignore --mode=lite --output=default,-inhx032 -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s" build/default/production/serial.p1
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.82
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)
make[2]: *** [dist/default/production/Tempsensor.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
:0: error: undefined symbols:
_uart_read(dist/default/production\Tempsensor.X.production.obj) _uart_write(dist/default/production\Tempsensor.X.production.obj)
make[2]: Leaving directory `C:/Users/xz4phd/Desktop/PicDem 2 Project/PIC16F/Code/Tempsensor.X'
make[1]: Leaving directory `C:/Users/xz4phd/Desktop/PicDem 2 Project/PIC16F/Code/Tempsensor.X'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)
 
Go to my tutorials in my signature and grab tutorial 11.4 You can copy the RS232 code and use it....
 
i went through that but its not working.
iam not geting any output.build is succesful.
my pic2 demo kit shows blank when i debug and run this code.but there are no errors.i am not getting why

#include <stdio.h>
#include <stdlib.h>
#include<htc.h>

#include<pic.h>

#define _XTAL_FREQ 4000000

#define BAUD2400_16MHZ 103
#define BAUD2400_4MHZ 25

__CONFIG(0x2F84);
__CONFIG(0x1EFF);



void usart_init(void)
{
TRISC7 = 1;
TRISC6 = 0;
SPBRG = 25; // 4mhz xtal 9600 BAUD
TXEN = 1;
CREN = 1;
SPEN = 1; // SPEN and CREN
}
void usart_putc(unsigned char c)
{
while(!TXIF);
TXREG = c;
}

void usart_puts(unsigned char *s)
{
while(*s)
{
usart_putc (*s);
}
}



void main()
{

usart_init();
RCIE =1;
GIE = 1;
PEIE = 1;
usart_puts("Test");
while(1);
}
 
This code you posted will not work either.... You are trying to print a constant string......Read through the comments in the tutorial..

There are two types of strings.... Constant and variable.... Basically Constant strings are hard coded and require a different pointer
Code:
void usart_puts(const char *s)
   {
      while(*s++ )
         {
          usart_putc (*s);
         }
   }

I use a buffer for output streams.. If you read through tutorial 11.4, look at the LCD_printC() and LCD_printR() routines...
 
i cant use the serial int functions as my include library dont have that files.
what should i do to make this program work.please help
 
Tooo many errors...

There is no need for <pic.h> if you use the <htc.h> (it will auto include the correct headers)
You have to set the OSCCON reg to 4mHz
You need to set the BRGH on this chip for a SPBRG of 25
I have included the "sprintf()" routine in my version.

This works:--

Code:
#include <stdio.h>		// sprintf() is in here
#include <stdlib.h>		// string functios are in here
#include <htc.h>		// You only need this for defines
   
#define _XTAL_FREQ 4000000

#define BAUD9600_16MHZ 103
#define BAUD9600_4MHZ 25

__CONFIG(0x2F84);
__CONFIG(0x1EFF);

unsigned char buffer[20];

void usart_init(void)
	{
	TRISC7 = 1;		// both of these
	TRISC6 = 1;		// MUST be input
	BRGH = 1;
	SPBRG = BAUD9600_4MHZ;	 // 4mhz xtal 9600 BAUD
	TXEN = 1;	
	CREN = 1;
	SPEN = 1;	 	// SPEN and CREN
	}
	
void usart_putc(const char c)
	{
	while(!TXIF);
	TXREG = c;
	}

void usart_puts(unsigned char *s)
	{
	while(*s)
		{
		usart_putc (*s++);
		}
	}

void main()
	{
	OSCCON = 0x68;		// THIS MUST BE SET
	_nop();
	_nop();				// Two clocks should do it
	usart_init();
	RCIE =1;
	GIE = 1;
	PEIE = 1;
	sprintf(buffer,"TEST");	// Using a buffer so the USART
	usart_puts(buffer);		// can send the data as variable...
	while(1);
	}
 
What LCD?..... There is no LCD in your code... Are you using a serial LCD?
 
I mean... Why are you bothered by the LCD being blank.... Your code isn't using the LCD... Aren't you just sending to PC / hyperterminal..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…