Simple assembly bit banging on PIC12f683 working reg issue

General discussion on mikroC.
Post Reply
Author
Message
jon6123
Posts: 1
Joined: 02 Jul 2016 19:57

Simple assembly bit banging on PIC12f683 working reg issue

#1 Post by jon6123 » 02 Jul 2016 20:00

Hi there!

I'm trying to control a ring of addressable LEDs (see datasheet below) by bit banging data using assembly language on a PIC 12f683 as it only accepts data at sub uS speeds, plus it feels like a good learning exercise for my fist time writing assembly!

So far using MikroC I have a function to control one colour on one LED by passing the function a char value.

However now I plan to progress with this code and intend to use the working register to store the data, but when I do so I can see on my oscilloscope the chip always sends the same value 0100 0001 no matter what I send, or even if I set a constant to W reg!

Any reason why this could be? perhaps this value (33/0x22) is an error value?

or perhaps this compare command BTFSS cannot be used with working reg?

any thoughts appreciated

Thanks for your time!

Working code:

Code: Select all

void ringasm(char a){

GPIO.B2 = 0;    //set output pin to zero

Delay_us(51);   // wait for LED chip to clear

asm {
    BSF        GPIO+0, 2              //set output to 1
    BTFSS      FARG_ringasm_a+0, 7    //if bit 7 of char is 1...
    BCF        GPIO+0, 2              //..skip this clearing of output
    BCF        GPIO+0, 2              //clear output
    NOP                               //do nothing

    BSF        GPIO+0, 2              //repeat for bit 6
    BTFSS      FARG_ringasm_a+0, 6
    BCF        GPIO+0, 2
    BCF        GPIO+0, 2
    NOP

    BSF        GPIO+0, 2           //repeat for bit 5
    etc...
    etc...
    etc for all bits to 0th bit...
non working code: (using working reg)

Code: Select all

void ringasm(char a){

GPIO.B2 = 0;    //set output pin to zero

Delay_us(51);   // wait for LED chip to clear

asm {

    CLRW                              //clear working reg
    MOVF       FARG_ringasm_a+0, 0    //move char to working reg

    BSF        GPIO+0, 2              //set output to 1
    BTFSS      W+0, 7                 //if bit 7 of working reg is 1...
    BCF        GPIO+0, 2              //..skip this clearing of output
    BCF        GPIO+0, 2              //clear output
    NOP                               //do nothing

    BSF        GPIO+0, 2              //repeat for bit 6
    BTFSS      W+0, 6
    BCF        GPIO+0, 2
    BCF        GPIO+0, 2
    NOP

    BSF        GPIO+0, 2              //repeat for bit 5 and rest of bits
    BTFSS      W+0, 5
    etc...
    etc...
/**********data sheets **************/

https://www.adafruit.com/images/product ... eet%20.pdf

http://akizukidenshi.com/download/ds/mi ... 12f683.pdf

Post Reply

Return to “mikroC General”