Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

load an address to a pointer variable

Status
Not open for further replies.

Dinuwilson

Advanced Member level 4
Joined
Aug 20, 2011
Messages
100
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
1,985
main()
{
int *a;
in my program i want to load the vale 0x06 as an address to pointer variable a

how can i load the value 0x06 to pointer variable a


please help me to solve this problam
 

thanks for your replay, i am use this code for pic microcontroller programming.

this is my code

#include<pic.h>

void main()
{
int *a;
TRISB=0X00;
int *a = (int *) 0x06 ;
a=0xFF;

}

here ox06 is the address of PORTB. i want to pass the value 0xFF to PORTB using
pointers.
 

thanks for your replay, i am use this code for pic microcontroller programming.

this is my code

#include<pic.h>

void main()
{
int *a;
TRISB=0X00;
int *a = (int *) 0x06 ;
a=0xFF;

}

here ox06 is the address of PORTB. i want to pass the value 0xFF to PORTB using
pointers.
in
Code:
    int *a = (int *) 0x06 ;
    a=0xFF;
you initialize a with the value 0x06 then assign it the value 0xFF, i.e. a now points to address 0xFF
you need to use the * operator to dereference a when you use it to write to port B, i.e.
Code:
    int *a = (int *) 0x06 ;
    *a=0xFF;
write 0xFF to address 0x06
 
if i use

int *a = (int *) 0x06 ;
*a=0xFF;

in mplab it show error. here i attach the error shows in mplab. error.JPG
 

running the following code (built using MPLAB 8.86 and HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.83)
Code:
#include <htc.h>

// delay function
void delay(int x)
{
	int i;
	for(i=0;i<10000;i++);
}

void main(void)
{
	unsigned char* portb=0x06;      // port B 
 	TRISB=0;
	*portb=0;
     while(1)
 		{
		delay(1000);
		*portb=!*portb;		// blink LED on portB
		}
}
on a PICDEM mechatronics board
**broken link removed**

it blinks LEDs connected to PORTB

not sure what you problem is - MPLAB should not crash! perhaps reinstall it and the complier
 

same error shows when i use you codeerror.JPG

- - - Updated - - -

same error shows when i use your codeerror.JPG
 

the following
Code:
#include <pic.h>

void main(void)
{
	int *a;
	TRISB=0X00;
	int *a=(int *) 0x06;
	*a=0xFF;
}
builds without errors, e.g.
Code:
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode)  V9.83
Copyright (C) 2011 Microchip Technology Inc.
(1273) Omniscient Code Generation not available in Lite mode (warning)

Memory Summary:
    Program space        used    1Bh (    27) of  2000h words   (  0.3%)
    Data space           used     4h (     4) of   160h bytes   (  1.1%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     0h (     0) of     1h word    (  0.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)


Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Lite mode.
See http://microchip.htsoft.com/portal/pic_pro for more information.
in fact it should give an error message as variable a is being defined twice (but should not crash MPLAB), try
Code:
#include <pic.h>

void main(void)
{
	TRISB=0X00;
	int *a=(int *) 0x06;
	*a=0xFF;
}
I note that the compiler that crashes is V9.6 - I am using V9.83
try reinstalling the latest MPLAB and compiler
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top