CH559sdccUSBHost
CH559sdccUSBHost copied to clipboard
pinMode function and ports use in general
While i'm getting things to work with the vscode/cmake template project, i've run into issues with the pinMode function. It's not working at all for me (sdcc 3.9.5). After doing some research i found out (here and here) that SFRs has to be accessed directly. Changing their values or even reading via pointers will not work. To overcome this problem and to make setting/controlling pins easier i wrote a kind of "acrobatic" macro generator, which will create a SBIT(name, portAddress, pinNumer); and a set of config functions.
https://gist.github.com/hexeguitar/f44e10b8c560d252de781d2f76a28ab9
Using is simple. First create a new pin somewhere at the top of the source file:
PORT_PIN(LED_1, 1, 0)
will create LED_1 on P1.0 and a set of functions:
SBIT(LED_1, 0x90, 0);
LED_1_in(); //set the put as input
LED_1_in_pu(); //set the pin as input+pullup
LED_1_out(); // push-pull output
LED_1_out_od(); // output open drain
LED_1_out_od2(); // output open drain 2clk
LED_1_inout_pu(); // bidirectional + pullup
LED_1_inout_pu2(); // bidirectional + pullup 2clk
Set the desired more using one of them. Controlling the output state will be as easy as:
LED_1=1;
LED_1=0;
And here comes a significant limitation: if i now would like to use P1.2 as, let's say bidirectional+pullup I/O pin it will change the PORT_CFG setting for all the PORT1 pins. P10 will loose its push-pull capabilities. So, i think, when designing these chips in it will be safe to assume the outputs are open drain, use them to drive active low inputs and with external stronger pull ups if necessary.
Hope that helps and will be useful! Piotr
Thank you for that info, i was always wondering why the pointer array method did not work.
I will leave it open here :)