INCLUDE"P18F4550.INC" ;include PIC18F4580 definitions
ORG 0000H ;reset vector location
CLRF PCLATH ;clearing program counter higher bits
GOTO START ;jump to start up location defined at 30H
ORG 0030H
START ;start of program
BCF TRISC,6 ; configure RC6(TXD pin) as o/p [B]According to me this line is wrong as it is mentioned in data sheet that Rx and Tx pins TRIS value must be Set[/B]
BCF TXSTA,BRGH ; select baud-rate(9600)
BCF BAUDCON,BRG16 ; 8-bit Baud Rate Generator, SPBRG only
; value loaded corresponding to baud-rate,9600
MOVLW 0x4D
MOVWF SPBRG
BCF TXSTA,SYNC ; asynchronous mode select
BSF TXSTA,TXEN ; 8-bit transmission enable
BSF RCSTA,SPEN ; serial port enable
MOVLW 'S'
MOVWF TXREG ;transmit buffer loaded with data to be transmitted
CHECK
BTFSS TXSTA,TRMT ;wait for complete transmission and skip if done
GOTO CHECK
GOTO $ ;infinite wait
END ;end of program
#include<htc.h>
/***************************
* Device configuration *
***************************/
#pragma config FOSC = HS // Using 20 MHz crystal with PLL
//#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
//#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
#define TX TRISCbits.RC6
#define RX TRISCbits.RC7
void delay_ms(unsigned int time);
void delay_us(unsigned int time);
//void SerTX(unsigned char value);
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
delay_ms(1000);
PORTB = 0xFF;
delay_ms(1000);
TRISCbits.RC6 = 0;
TRISCbits.RC7 = 1; //Make Input Pin
TXSTAbits.BRGH = 0; //Select Low Speed Baud Rate
BAUDCONbits.BRG16 = 0; //Select 8-bit Baud Rate Generator Only
SPBRGH = 0x4D; //[B][I]Even when i change this value to 129 and BRGH to 1 i am getting the same result[/I][/B]
TXSTAbits.SYNC = 0; //Asynchronous Mode Selected
TXSTAbits.TXEN = 1; //8-bit Transmit mode enable
RCSTAbits.SPEN = 1; //Enable Serial Port Transmission
while(1)
{
TXREG = 'S';
while(TXSTAbits.TRMT == 0);
PORTB = 0x00;
delay_ms(1000);
PORTB = 0xFF;
}
}
/*void SerTX(unsigned char value)
{
TXREG = value;
while(TXSTAbits.TRMT == 0);
}*/
void delay_us(unsigned int time)
{
unsigned int k;
for(k=0;k<time;k++)
{
_delay(5);
}
}
void delay_ms(unsigned int time)
{
unsigned int k;
for(k=0;k<time;k++)
{
delay_us(1000);
}
}
I am using Hi-Tech PICC18 Compiler.
My Board has 20Mhz Crystal
In my C code i had configured the Configuration Bits as HS for 20 Mhz not for HS_PLL mode..
So i think it should work..
I don't know what mistake i am doing...
In my c code
i had replaced the SPBRG value by 129 even that did not works :-(
#include<htc.h>
#include "delay.h"
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
DelayMs(1000);
TRISCbits.RC6 = 1;
TRISCbits.RC7 = 1; //Make Input Pin
TXSTAbits.BRGH = 0; //Select Low Speed Baud Rate
BAUDCONbits.BRG16 = 0; //Select 8-bit Baud Rate Generator Only
SPBRGH = 0x4D;
TXSTAbits.SYNC = 0; //Asynchronous Mode Selected
TXSTAbits.TXEN = 1; //8-bit Transmit mode enable
RCSTA = 0x80;
while(1)
{
TXREG = 'S';
while(PIR1bits.TXIF == 0);
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
DelayMs(1000);
}
}
bit 4 TXIF: EUSART Transmit Interrupt Flag bit
1 = The EUSART transmit buffer, TXREG, is empty (cleared when TXREG is written)
0 = The EUSART transmit buffer is full
#include "p18f4550.h"
#include "delays.h"
#include "usart.h"
/*********Setting Configuration Bits************/
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
/***********************************************/
void DelayMs(unsigned int itime);
unsigned int i;
void main()
{
TRISB = 0x00;
PORTB = 0xFF;
DelayMs(1000);
// configure USART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,77 );
DelayMs(10);
while(BusyUSART()); //Wait Until USART gets Ready
DelayMs(10);
for(i=0;i<10;i++)
{
WriteUSART('A');
DelayMs(1000);
}
CloseUSART();
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
while(1);
}
void DelayMs(unsigned int itime)
{
unsigned int k;
for(k=0;k<itime/2;k++)
{
Delay10KTCYx(1);
}
}
#include "p18f4550.h"
#include "delays.h"
#include "usart.h"
/*********Setting Configuration Bits************/
#pragma config FOSC = HS [B][I]Only 20Mhz Oscillator[/I][/B]
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
/***********************************************/
void DelayMs(unsigned int itime);
unsigned int i;
void main()
{
TRISB = 0x00;
PORTB = 0xFF;
DelayMs(1000);
// configure USART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH,129 ); [B][I]//To get 9600 Baud rate[/I][/B]
DelayMs(10);
while(BusyUSART()); //Wait Until USART gets Ready
DelayMs(10);
for(i=0;i<10;i++)
{
WriteUSART('A');
DelayMs(1000);
}
CloseUSART();
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
while(1);
}
void DelayMs(unsigned int itime)
{
unsigned int k;
for(k=0;k<itime/2;k++)
{
Delay10KTCYx(1);
}
}
#include<htc.h>
#include "delay.h"
///***************************
//* Device configuration *
//***************************/
#pragma config FOSC = HS // Using 20 MHz crystal with PLL
//#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
//#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
#define TX TRISCbits.RC6
#define RX TRISCbits.RC7
//void SerTX(unsigned char value);
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
DelayMs(1000);
TRISCbits.RC6 = 0;
TRISCbits.RC7 = 1; //Make Input Pin
TXREG = 0x00;
SPBRG = 129;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
TXSTAbits.BRGH = 1;
BRG16 = 0;
while(1)
{
while(PIR1bits.TXIF == 0);
TXREG = 'A';
DelayMs(1000);
}
}
#include<htc.h>
#include "delay.h"
///***************************
//* Device configuration *
//***************************/
#pragma config FOSC = HS // Using 20 MHz crystal with PLL
//#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
//#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
#define TX TRISCbits.RC6
#define RX TRISCbits.RC7
//void SerTX(unsigned char value);
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
DelayMs(1000);
TRISCbits.RC6 = 0;
TRISCbits.RC7 = 1; //Make Input Pin
TXREG = 0x00;
SPBRG = 77;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
TXSTAbits.BRGH = 0;
BRG16 = 0;
while(1)
{
while(PIR1bits.TXIF == 0);
TXREG = 'A';
DelayMs(1000);
}
}
I think my Bootloader is not able to program the configuration bits..
And has a default config setting for all cases..
Am i right..
Now a question i want to ask
Are bootloaders able to program the configuration bits..
7.1 EECON1 and EECON2 Registers
Access to the data EEPROM is controlled by two
registers: EECON1 and EECON2. These are the same
registers which control access to the program memory
and are used in a similar manner for the data
EEPROM.
The EECON1 register (Register 7-1) is the control
register for data and program memory access. Control
bit, EEPGD, determines if the access will be to program
or data EEPROM memory. When clear, operations will
access the data EEPROM memory. When set, program
memory is accessed.
Control bit, CFGS, determines if the access will be to
the Configuration registers or to program memory/data
EEPROM memory. When set, subsequent operations
access Configuration registers. When CFGS is clear,
the EEPGD bit selects either Flash program or data
EEPROM memory.
The WREN bit, when set, will allow a write operation.
On power-up, the WREN bit is clear. The WRERR bit is
set in hardware when the WREN bit is set and cleared
when the internal programming timer expires and the
write operation is complete.
25.1 Configuration Bits
The Configuration bits can be programmed (read as
‘0’) or left unprogrammed (read as ‘1’) to select various
device configurations. These bits are mapped starting
at program memory location 300000h.
The user will note that address 300000h is beyond the
user program memory space. In fact, it belongs to the
configuration memory space (300000h-3FFFFFh),
which can only be accessed using table reads and
table writes.
Programming the Configuration registers is done in a
manner similar to programming the Flash memory. The
WR bit in the EECON1 register starts a self-timed write
to the Configuration register. In normal operation mode,
a TBLWT instruction, with the TBLPTR pointing to the
Configuration register, sets up the address and the
data for the Configuration register write. Setting the WR
bit starts a long write to the Configuration register. The
Configuration registers are written a byte at a time. To
write or erase a configuration cell, a TBLWT instruction
can write a ‘1’ or a ‘0’ into the cell. For additional details
on Flash programming, refer to Section 6.5 “Writing
to Flash Program Memory”.
I think configuring the configuration bits using the above technology..
But will it affect the bootloader code in my controller..
I will run my code with 48Mhz Crystal..
#include<htc.h>
#include "delay.h"
///***************************
//* Device configuration *
//***************************/
#pragma config FOSC = HS // Using 20 MHz
//#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
//#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
#define TX TRISCbits.RC6
#define RX TRISCbits.RC7
//void SerTX(unsigned char value);
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
DelayMs(1000);
PORTB = 0xFF;
DelayMs(1000);
TRISCbits.RC6 = 0;
TRISCbits.RC7 = 1; //Make Input Pin
TXREG = 0x00;
SPBRG = 77;
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
TXSTAbits.BRGH = 0;
BRG16 = 0;
while(1)
{
while(PIR1bits.TXIF == 0);
TXREG = 'A';
DelayMs(1000);
}
}
My Bootloader is not changing the configuration bits..
Maybe you should try changing the Configuration Registers in a small demo program?
You should also consider replacing the bootloader with one that is well documented and source code is available.
Maybe you should try changing the Configuration Registers in a small demo program?
You should also consider replacing the bootloader with one that is well documented and source code is available.
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?