CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SFRs access

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

SFRs access
PostPosted: Sat Aug 09, 2014 4:09 am     Reply with quote

Why we cant access SFRs by using pointers?
MB its safety precaution?!?
_________________
A person who never made a mistake never tried anything new.
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 5:28 am     Reply with quote

You need to show us your code as there is no technical reason why you can't.

jay
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 7:10 am     Reply with quote

Code:

#include <18F4620.h>
#DEVICE *=16
#use delay(clock=40000000)
#fuses H4, NOWDT, NOLVP, NODEBUG
#use rs232(BAUD=9600, UART1, errors)

#define BUTT PIN_A4
#define BUTT_PRESSED (!INPUT(BUTT))
#define G_LED PIN_A5
#define R_LED PIN_B5
#define Y_LED PIN_B4

#DEFINE LED_OFF(X) OUTPUT_HIGH(X)
#DEFINE LED_ON(X) OUTPUT_LOW(X)

#define LCD_ENABLE_PIN  PIN_E2
#define LCD_RS_PIN      PIN_E0
#define LCD_RW_PIN      PIN_E1
#define LCD_DATA4       PIN_D4
#define LCD_DATA5       PIN_D5
#define LCD_DATA6       PIN_D6
#define LCD_DATA7       PIN_D7

#include <lcd.c>

void *port_b_ponter;

void chip_init(void)
{
   led_off(r_led);
   led_off(y_led);
   led_off(g_led);
   port_b_ponter = getenv ("SFR:PORTB");
   set_tris_b(0xFF);   
   lcd_init();
   
}
void main()
{
chip_init();
   while (true)
   {
   *port_b_ponter = 0xFF;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   *port_b_ponter = 0x00;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   }
}

_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 8:57 am     Reply with quote

You need to cast the pointer to a type, or actually make the pointer be to a type. A void pointer, does not know how large the object it points to is, until it is told how large this object is. Some languages _assume_ a size, but this is not correct.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 9:42 am     Reply with quote

OMG I just noticed that I have adjusted the TRIS as inputs.
It works now.
Nevertheless the pointer doesn't have a type, it works.
I might be a problem if increment the pointer (since it doesn't know the memory block length(I dont know what the default for void is. . .)) but it works with void type, structured this way.

I cant believe I didn't notice this (TRIS as inputs).
Excuse me I lost your time.
This way it works, despite of void type of pointer.
As long as I don't increment/ decrement the pointer here is no problem with the void type (my opinion and test approved).

Code:

#include <18F4620.h>
#DEVICE *=16
#use delay(clock=40000000)
#fuses H4, NOWDT, NOLVP, NODEBUG
#use rs232(BAUD=9600, UART1, errors)

#define BUTT PIN_A4
#define BUTT_PRESSED (!INPUT(BUTT))
#define G_LED PIN_A5
#define R_LED PIN_B5
#define Y_LED PIN_B4

#DEFINE LED_OFF(X) OUTPUT_HIGH(X)
#DEFINE LED_ON(X) OUTPUT_LOW(X)

#define LCD_ENABLE_PIN  PIN_E2
#define LCD_RS_PIN      PIN_E0
#define LCD_RW_PIN      PIN_E1
#define LCD_DATA4       PIN_D4
#define LCD_DATA5       PIN_D5
#define LCD_DATA6       PIN_D6
#define LCD_DATA7       PIN_D7

#include <lcd.c>

void *port_b_ponter;

void chip_init(void)
{
   led_off(r_led);
   led_off(y_led);
   led_off(g_led);
   port_b_ponter = getenv ("SFR:PORTB");
   set_tris_b(0x00);                //Problem was actualu here
   lcd_init();
   
}
void main()
{
chip_init();
   while (true)
   {
   *port_b_ponter = 0xFF;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   *port_b_ponter = 0x00;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   }
}

_________________
A person who never made a mistake never tried anything new.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 9:44 am     Reply with quote

OMG I just noticed that I have adjusted the TRIS as inputs.
It works now.
Nevertheless the pointer doesn't have a type, it works.
I might be a problem if increment the pointer (since it doesn't know the memory block length(I dont know what the default for void is. . .)) but it works with void type, structured this way.

I cant believe I didn't notice this (TRIS as inputs).
Excuse me I lost your time.
This way it works, despite of void type of pointer.
As long as I don't increment/ decrement the pointer here is no problem with the void type (my opinion and test approved).

Code:

#include <18F4620.h>
#DEVICE *=16
#use delay(clock=40000000)
#fuses H4, NOWDT, NOLVP, NODEBUG
#use rs232(BAUD=9600, UART1, errors)

#define BUTT PIN_A4
#define BUTT_PRESSED (!INPUT(BUTT))
#define G_LED PIN_A5
#define R_LED PIN_B5
#define Y_LED PIN_B4

#DEFINE LED_OFF(X) OUTPUT_HIGH(X)
#DEFINE LED_ON(X) OUTPUT_LOW(X)

#define LCD_ENABLE_PIN  PIN_E2
#define LCD_RS_PIN      PIN_E0
#define LCD_RW_PIN      PIN_E1
#define LCD_DATA4       PIN_D4
#define LCD_DATA5       PIN_D5
#define LCD_DATA6       PIN_D6
#define LCD_DATA7       PIN_D7

#include <lcd.c>

void *port_b_ponter;

void chip_init(void)
{
   led_off(r_led);
   led_off(y_led);
   led_off(g_led);
   port_b_ponter = getenv ("SFR:PORTB");
   set_tris_b(0x00);                //Problem was actualu here
   lcd_init();
   
}
void main()
{
chip_init();
   while (true)
   {
   *port_b_ponter = 0xFF;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   *port_b_ponter = 0x00;
   printf(lcd_putc,"\fAddress = 0x%lX \nValue of reg = 0x%X", port_b_ponter, *port_b_ponter);
   delay_ms(500);
   }
}

_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 1:52 pm     Reply with quote

You are implicitly casting, when you read the object inside printf (you read an int). However it will fail if you add an offset, or do any actual pointer operation. Since there is no 'point' in using pointers except to perform a pointer operation, it is important to use a type.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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