|
|
View previous topic :: View next topic |
Author |
Message |
neal1 Guest
|
How to access the internal register (16f628a) |
Posted: Tue Feb 24, 2009 11:23 am |
|
|
hi, I'm newbie here.....I just start using this ccs c compiler recently.
I wish to access SPBRG(99h) register and CMCON register and other registers.
Below is my code:
Code: |
#include "F:\serial_port\test7\t7.h"
#include <ctype.h>
//do i need add any other .h file such as pic.h?
//the t7.h is the default file that generate using PIC WIZARD n attached //at bottom
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
// TODO: USER CODE!!
SET_TRIS_A(00000000);
SET_TRIS_b(00000010);
// i wish load some value into CMCON but not successfully
// compiler said that it(CMCON) is not defined.
//CMCON = 0x07;
//0x07 is the value that i wish loaded into CMCON
}
//t7.h coding as below
/*
#include <16F648A.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)
*/ |
|
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 24, 2009 11:28 am |
|
|
#byte CMCON=0x99
Then you can write to this register. There is a posted list here (a search for register name definitions, with 'search for all terms' selected, will find it), which can be loaded to give standard names for 99% of the registers.
However the reason it is not defined as standard, is that you don't need it.
If you have a #use RS232 statement, the compiler _automatically loads the register for you_. To change the setting, you can just use 'set_uart_speed(BAUD RATE);', and the compiler will calculate the value and load it for you.
Best Wishes |
|
|
neal1 Guest
|
|
Posted: Tue Feb 24, 2009 12:09 pm |
|
|
hi Ttelmah,
u mean write like this way?
#byte CMCON=0x99; //define the CMCON at the 99h address
COMCON = 0x07;// load the value into it
and i would like to ask y my #use RS232 did not load the register for me? am i done any things wrong? or where i should put the " #use RS232 "? for this moment i put it at ".h" file |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 24, 2009 3:07 pm |
|
|
You show the four 'essential' lines remmed out in your t7.h file....
Get rid of the /* */ round these.
However there are then 'comments' about these. You are selecting 'HS', which is the oscillator fuse for more than 4MHz, but have the clock statement saying that your clock is 4MHz. You should be using either XT, if you have a 4MHz crystal, or set the clock statement to the right value, if you are using a faster crystal. HS is 'borderline', on some crystals at 4MHz. You have no power up timer selected, but generally operation is more reliable with PUT selected. You have the MCLR pin enabled, have you got a pull up on this?. You have brownout selected, but on these chips, the brownout is at a fixed 4v (nominal, and can be as high as 4.35v. This option _must not be selected_, if you are operating on anything below 5v....
If these options are correct, then removing the remarks from round these lines should make your chip work.
Best Wishes |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Feb 24, 2009 3:17 pm |
|
|
neal1
btw your #byte should NOT have a semicolon after it.
Quote: | #byte CMCON=0x99; //define the CMCON at the 99h address |
Should be
Code: | #byte CMCON=0x99 //define the CMCON at the 99h address |
|
|
|
neal1 Guest
|
|
Posted: Wed Feb 25, 2009 4:07 am |
|
|
i juz wan to double confirm that if i write
#byte CMCON=0x1f
this mean i define CMCON at 1fh right?
and this will be the same as the internal register in 16f628a right/? |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Wed Feb 25, 2009 7:18 am |
|
|
neal1 wrote: | i juz wan to double confirm that if i write
#byte CMCON=0x1f
this mean i define CMCON at 1fh right?
and this will be the same as the internal register in 16f628a right/? |
yes, you can access that register then.
Btw, you can also do something like this:
Code: | #byte CMCON=getenv("SFR:CMCON") |
Which ensures that CMCON will always be appropriate regardless the target device. |
|
|
neal1 Guest
|
|
Posted: Wed Feb 25, 2009 10:29 am |
|
|
erm....what if i just want to bit4 of certain register is HIGH or LOW? How i should set it?
eg:
I would like to set BIT2 of TXSTA is HIGH. How i should write the code? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|