I know this is very basic if you know the way to control the pins on ports. I am stuck.
DDRD = 0xFF; // Set the pins as outputs
PORTD = 0xFF; // Turns on the pullups
How do you set PD0 low. This does not work PORTD_PDO = 0x00;
Ray.
Solved! Go to Solution.
Hi Ray,
maybe I don't understand.
I just tested the code on my side, I can see portd bit0 at memory 0x0005 got toggled with
PORTD_PD0=0x00; //set output pin as low
asm nop;
PORTD_PD0=0x01; //set output pin as high
see attached video.
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I have it now working. I am not sure if there is a better way to control the pins. This works.
PUCR |= 0x08; | //set pull up on Port D |
DDRD_DDRD0=0x01; // set direction as output
for(;;) {
PORTD |= PORTD_PD0; | |
Delay_ms(2000); | |
PORTD = ~PORTD_PD0; | |
_FEED_COP(); /* feeds the dog */ |
} /* loop forever */
It is weird how you must use PORT_PD0 and 0x01 is ignored.
Ray.
Hi,
to make the proper port off again try to and it with the neg. value of the port.
PORTD &= ~(PORTD_PD0);
Martin,
I get nothing when using.
PORTD |= PORTD_PD0;
asm nop;
PORTD &= ~PORTD_PD0;
This works...
PORTD = 0x01;
asm nop;
PORTD = 0x00;
So does this...
PORTD |= (1<<0);
asm nop;
PORTD &= ~(1<<0);
They work correctly as long as I do not use my delay method. See reply to Zhang.
Ray.
hi Ray,
it is not "must", I just do a quick test if PORT_PD0 can function normal. you can modify the code as your requirement.
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Zhang,
it is not "must", I just do a quick test if PORT_PD0 can function normal. you can modify the code as your requirement.
It is not that I want to modify your example. It is that this did not work.
PORTD_PD0=0x00; //set output pin as low
asm nop;
PORTD_PD0=0x01; //set output pin as high
I would have expected your example to work as that is what I have used with other MCU. I wish someone could explain what possible reason you cannot set the bits for the pins.
Ray.
Hi Ray,
maybe I don't understand.
I just tested the code on my side, I can see portd bit0 at memory 0x0005 got toggled with
PORTD_PD0=0x00; //set output pin as low
asm nop;
PORTD_PD0=0x01; //set output pin as high
see attached video.
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Zhang,
If I use this code I get this pattern on my oscilloscope. http://www.turbofast.com.au/tfbin/TEK0000.JPG which is correct.
PORTD |= (1<<0);
asm nop;
PORTD &= ~(1<<0);
If I use this code I get this pattern which is wrong. http://www.turbofast.com.au/tfbin/TEK0001.JPG
PORTD |= (1<<0);
Delay_us(1);
PORTD &= ~(1<<0);
For some reason my delay method is causing problems. This is its code.
#define F_BUS 50 // 50mHz
#define LOOP_US ((F_BUS*1000000/6000000)+1)
void Delay_us(unsigned short ms){
unsigned short j, k;
for(j=0;j<ms;j++){
for(k=0;k<LOOP_US;k++){
}
}
}
Ray.
Sorry....My delay method is working correctly. The code should have another delay like this.
PORTD |= (1<<0);
Delay_us(1);
PORTD &= ~(1<<0);
Delay_us(1);
Sorry for all the confusion. Thank you all, for your help.
Ray.
Hi Ray,
please refer this code:
PUCR = 0x08; | //set pull up |
DDRD_DDRD0=0x01; // set direction as output
PORTD_PD0=0x00; //set output pin as low
asm nop;
PORTD_PD0=0x01; //set output pin as high
can this help?
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Zhang,
I have found that you cannot set the pullup like this. PUCR = 0x08; It causes debug break point errors.
You have to use PUCR |= 0x08;
To set Port C and D pullups you cannot use PURC = 0x0C;
You have to do this...
PUCR |= 0x04;
PUCR |= 0x08;
I still cannot set the pins high or low, and need help with this. Why is such a basic thing so hard..
Ray.
Zhang,
I get a ILLEGAL_BP when I use the PURC = 0x08; and the pin does not change.
This is my test code,
PUCR = 0x08; | //set pull up |
DDRD_DDRD0=0x01; // set direction as output
for(;;) {
PORTD_PD0=0x00; //set output pin as low | |
Delay_ms(2000); | |
PORTD_PD0=0x01; //set output pin as high |
;
_FEED_COP(); /* feeds the dog */ |
} /* loop forever */
This below does work...Why ?
DDRD = 0x01;
PORTD = 0x01;
for(;;) {
Delay_ms(2000);
PORTD_PD0 = ~PORTD_PD0;
_FEED_COP(); /* feeds the dog */
} /* loop forever */
Ray.
Ray, what MCU do you use?
iggi,
I am using the 144 pin S12XEP100
Ray.
please post here your project. thanks!
Have a great day,
Zhang Jun
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------