Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] pic 16f1824 problem with internal oscillator

Status
Not open for further replies.

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
thanks tahmid,finally i manage the clock frequency by setting osccon register ..but uart is not working my code is given below ..please help me...


void main()
{
OSCCON=0x72;
ANSELA=0;
TRISA0_bit=0;
UART1_Init(9600);
delay_ms(500) ;
TXCKSEL_bit=1;
RXDTSEL_bit=1;
CPSON_bit=0;
C1ON_bit=0;
GIE_bit=0;

TRISA1_bit=1;
TRISC5_bit=0;


TRISC4_bit=1;


// initialize UART1 module


while (1)
{
TXREG=0x01;
Delay_100ms();

} }
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
You have only initailized UART with 9600 baud. Where is the UART1_Read(), UART1_Read_Text(), UART1_Write(), or UART1_Write_Text() function?
What is your clock frequency? You have to Set comparator register properly. Actually you have to disable the comparators because they are connected to RA0 and RA1 pins.
 

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
You have only initailized UART with 9600 baud. Where is the UART1_Read(), UART1_Read_Text(), UART1_Write(), or UART1_Write_Text() function?
What is your clock frequency? You have to Set comparator register properly. Actually you have to disable the comparators because they are connected to RA0 and RA1 pins.
thank you for your reply
clock 8 mhz
i have set c1on_bit=0 and c2on_bit=0
but no change
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
What change are you expecting without sending are receiving any data?

Open your project in mikroC Pro and go to menu Project>Edit Project...

See attached image. Make your settings like that. Remove OSCCON settings in your code.
 

Attachments

Last edited:

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
On your keyboard, press Ctrl + Shift + E. At the top of the window that pops up, you have "Oscillator Selection", select INTOSC.

Hopet this helps.
Tahmid.
yeah i initially set like that but when i give a 1000 ms delay it will give a 10 - 15 seconds of delay.then i changed the osccon register and loaded with 0x72 the the delay was almost correct

- - - Updated - - -

instead of uart_write() i used txreg

- - - Updated - - -

i used txreg=0x01 instead of uart_write(0x01) ,is there any problem writing like that?

- - - Updated - - -

What change are you expecting without sending are receiving any data?
i used txreg=0x01 instead of uart_write(0x01) ,is there any problem writing like that?

- - - Updated - - -

i used txreg=0x01 instead of uart_write(0x01) ,is there any problem writing like that?
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
You have only initailized UART with 9600 baud. Where is the UART1_Read(), UART1_Read_Text(), UART1_Write(), or UART1_Write_Text() function?
What is your clock frequency? You have to Set comparator register properly. Actually you have to disable the comparators because they are connected to RA0 and RA1 pins.
thank you for your reply
clock 8 mhz
i have set c1on_bit=0 and c2on_bit=0
but no change
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
You have only initailized UART with 9600 baud. Where is the UART1_Read(), UART1_Read_Text(), UART1_Write(), or UART1_Write_Text() function?
What is your clock frequency? You have to Set comparator register properly. Actually you have to disable the comparators because they are connected to RA0 and RA1 pins.
thank you for your reply
clock 8 mhz
i have set c1on_bit=0 and c2on_bit=0
but no change

- - - Updated - - -

yes MCLR is pulled up

- - - Updated - - -

read my last post, it is updated. I don't know about writing to TXREG. I use UART Library functions in mikroC Pro. Are you sure writing a byte to TXREG will transmit the byte to Virtual Terminal?

See this link http://saeedsolutions.blogspot.in/2012/11/pic16f877-uart-code-proteus-simulation.html

Can you show me these registers in datasheet? mention the page nos.

TXCKSEL_bit=1;
RXDTSEL_bit=1;
CPSON_bit=0;
122 and 333

- - - Updated - - -

it is not working.but when i tried to toggle a port pin it worked
so it is clear that pic is working
the problem is with uart
i dont know how to clear it
please help me

- - - Updated - - -

What? You reposted your last post. Have you pulled-up MCLR pin to Vcc? If not, do it. Can you post your circuit?
i have checked voltages at mclr and vdd it is about 4.7 v
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
I saw about that registers. you are sending 0x01 to TXREG. See ASCII table 0x01 means SOH. Maybe it doesn't have a character. Try sending 48 decimal or 0x30. You should get character 0 on hyperterminal/proteus virtual terminal.

Also try UART1_Write('A'); and see if it outputs character A.

Also try setting TRISA0_bit = 1; and TRISA1_bit = 1;
 

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
I saw about that registers. you are sending 0x01 to TXREG. See ASCII table 0x01 means SOH. Maybe it doesn't have a character. Try sending 48 decimal or 0x30. You should get character 0 on hyperterminal/proteus virtual terminal.

Also try UART1_Write('A'); and see if it outputs character A.

Also try setting TRISA0_bit = 1; and TRISA1_bit = 1;
i tried with uart1_write('*');
didnt work.
setting both pins as input,i thought transmitter must be output..
let me try it
 

sarathsnairpoonjar

Member level 2
Joined
Nov 12, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Cochin,Kerala,India
Activity points
1,560
Did you select internal oscillator in the configuration settings? Do select it. Then, set the frequency of operation using the OSCCON register and the OSCTUNE register.
i have configured OSCCON ,Why should we configure OSCTUNE ,We have already set bits for 8mhz in osccon register is is necesseray to load values in OSCTUNE

- - - Updated - - -

OK. i got the output properly but using external oscillator. The problem is with Internal oscillator for sure. I will try to solve.
What is the frequency of the crystal you used in the circuit
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top