View previous topic :: View next topic |
Author |
Message |
rnd87
Joined: 10 Aug 2010 Posts: 3
|
Directly register access |
Posted: Wed Aug 18, 2010 7:32 am |
|
|
I would like to access register directly.And I have written these codes shown below;
Code: |
#include <18F13K50.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOXINST //Extended set extension and Indexed
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
#byte TRISB = 0x93 ///Register adress from its datasheet
#byte PORTB = 0x81 ///Register adress from its datasheet
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
TRISB=0x00;
while(true)
{
PORTB = 0x00; //All portb outputs should be 0(low level).
}
}
|
But it doesn't worked.Could you propose any idea for this mistake? |
|
|
theasus
Joined: 31 May 2009 Posts: 79
|
|
Posted: Wed Aug 18, 2010 8:03 am |
|
|
For directly register, You can use "View>Special Registers" option. After you generated "<PIC18F13K50_registers.h>" you can easily access register directly for example:
Code: |
#include <18F13K50.h>
#include <PIC18F13K50_registers.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV19
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES TO
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HFOFST
#FUSES WRT0
#FUSES WRT1
#FUSES USBDIV2
#FUSES BBSIZ2K //2K words Boot Block size
#FUSES PLLEN
#FUSES CPUDIV4 //System Clock by 4
#FUSES PCLKEN
#use delay(clock=20000000)
void main()
{
TRISB=0x00;
PORTB=0x00;
}
|
And "#include <PIC18F13K50_registers.h>" contains the adress of register you need;
Code: |
#byte TOSU = 0xFFF
#word TOS = 0xFFE
#byte STKPTR = 0xFFC
#byte PCLATU = 0xFFB
#byte PCLATH = 0xFFA
#byte PCL = 0xFF9
#byte TBLPTRU = 0xFF8
#word TBLPTR = 0xFF7
#byte TABLAT = 0xFF5
#word PROD = 0xFF4
#byte INTCON = 0xFF2
#byte INTCON2 = 0xFF1
#byte INTCON3 = 0xFF0
#byte INDF0 = 0xFEF
#byte POSTINC0 = 0xFEE
#byte POSTDEC0 = 0xFED
#byte PREINC0 = 0xFEC
#byte PLUSW0 = 0xFEB
#word FSR0 = 0xFEA
#byte WREG = 0xFE8
#byte INDF1 = 0xFE7
#byte POSTINC1 = 0xFE6
#byte POSTDEC1 = 0xFE5
#byte PREINC1 = 0xFE4
#byte PLUSW1 = 0xFE3
#word FSR1 = 0xFE2
#byte BSR = 0xFE0
#byte INDF2 = 0xFDF
#byte POSTINC2 = 0xFDE
#byte POSTDEC2 = 0xFDD
#byte PREINC2 = 0xFDC
#byte PLUSW2 = 0xFDB
#word FSR2 = 0xFDA
#byte STATUS = 0xFD8
#word TMR0 = 0xFD7
#byte T0CON = 0xFD5
#byte OSCCON = 0xFD3
#byte OSCCON2 = 0xFD2
#byte WDTCON = 0xFD1
#byte RCON = 0xFD0
#word TMR1 = 0xFCF
#byte T1CON = 0xFCD
#byte TMR2 = 0xFCC
#byte PR2 = 0xFCB
#byte T2CON = 0xFCA
#byte SSPBUF = 0xFC9
#byte SSPADD = 0xFC8
#byte SSPSTAT = 0xFC7
#byte SSPCON1 = 0xFC6
#byte SSPCON2 = 0xFC5
#word ADRES = 0xFC4
#byte ADCON0 = 0xFC2
#byte ADCON1 = 0xFC1
#byte ADCON2 = 0xFC0
#word CCPR1 = 0xFBF
#byte CCP1CON = 0xFBD
#byte REFCON2 = 0xFBC
#byte REFCON1 = 0xFBB
#byte REFCON0 = 0xFBA
#byte PSTRCON = 0xFB9
#byte BAUDCON = 0xFB8
#byte PWM1CON = 0xFB7
#byte ECCP1AS = 0xFB6
#word TMR3 = 0xFB3
#byte T3CON = 0xFB1
#byte SPBRGH = 0xFB0
#byte SPBRG = 0xFAF
#byte RCREG = 0xFAE
#byte TXREG = 0xFAD
#byte TXSTA = 0xFAC
#byte RCSTA = 0xFAB
#byte EEADRH = 0xFAA
#byte EEADR = 0xFA9
#byte EEDATA = 0xFA8
#byte EECON2 = 0xFA7
#byte EECON1 = 0xFA6
#byte IPR2 = 0xFA2
#byte PIR2 = 0xFA1
#byte PIE2 = 0xFA0
#byte IPR1 = 0xF9F
#byte PIR1 = 0xF9E
#byte PIE1 = 0xF9D
#byte OSCTUNE = 0xF9B
#byte TRISC = 0xF94
#byte TRISB = 0xF93
#byte TRISA = 0xF92
#byte LATC = 0xF8B
#byte LATB = 0xF8A
#byte LATA = 0xF89
#byte PORTC = 0xF82
#byte PORTB = 0xF81
#byte PORTA = 0xF80
#byte ANSELH = 0xF7F
#byte ANSEL = 0xF7E
#byte IOCB = 0xF7A
#byte IOCA = 0xF79
#byte WPUB = 0xF78
#byte WPUA = 0xF77
#byte SLRCON = 0xF76
#byte SSPMSK = 0xF6F
#byte CM1CON0 = 0xF6D
#byte CM2CON1 = 0xF6C
#byte CM2CON0 = 0xF6B
#byte SRCON1 = 0xF69
#byte SRCON0 = 0xF68
#byte UCON = 0xF64
#byte USTAT = 0xF63
#byte UIR = 0xF62
#byte UCFG = 0xF61
#byte UIE = 0xF60
#byte UEIR = 0xF5F
#word UFRM = 0xF5E
#byte UADDR = 0xF5C
#byte UEIE = 0xF5B
#byte UEP7 = 0xF5A
#byte UEP6 = 0xF59
#byte UEP5 = 0xF58
#byte UEP4 = 0xF57
#byte UEP3 = 0xF56
#byte UEP2 = 0xF55
#byte UEP1 = 0xF54
#byte UEP0 = 0xF53
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19561
|
|
Posted: Wed Aug 18, 2010 9:33 am |
|
|
and the key error is that PORTB, is not at address 0x81, and TRISB, is not at 0x93...
It certainly does _not_ give these addresses in "it's datasheet".
The numbers are not even right for a PIC16 (which does have the registers down in this area)....
As rnd87 has pointed out, you can ask the compiler to generate the addresses for you (if you have the windows version).
If you are going to use direct register access, you must get the numbers right.
Best Wishes |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Aug 18, 2010 11:49 am |
|
|
Another easy method to get a register you want (if you trust the compiler version) is:
#byte PORTB = getenv("sfr:PORTB")
And then no matter where the address is on a given chip, you'll get the address you want.
This makes the code a little more portable within CCS.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|