1
\$\begingroup\$

I am trying to light a LED with a PIC10F206, a PICkit4, the IDE MPLAB X IDE v5.40, and the pic-as Assembler.
This is what I tried:

#include <xc.inc>
    
    CONFIG CP=OFF
    CONFIG MCLRE=OFF
    
    ORG 0x0000
    
INIT:
  MOVLW 0010B    ;make GP1 an output pin
  MOVWF TRISGPIO ;move content of working reg to TRISGPIO (this is the first error)
  MOVLW 1101B    ;set GP1 output low so that the LED with pullup res. lights up
  MOVWF GPIO     ;move working reg to GPIO
  
LOOP:
  GOTO LOOP ;loop forever
END ;needed to end the program

The output is:

error: (800) undefined symbol "TRISGPIO"

I am trying to make GP1 an output pin and set the output of GP1 to 0 because I have the positive power supply on the other side of the LED.
According to the datasheet on page 21 TRISGPIO is a register.
And according to what I read online it is responsible for deciding if a pin is input or output.
So I put the bits 0010B in the working register. (so that GP0 is input, GP1 is output, GP2 is input, GP3 is input)
And then tried to put them into TRISGPIO.
I spent some hours digging through the microchip documentation but it's not really understandable for a beginner and tutorials are no longer valid.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Try "TRIS GPIO". Note that "TRIS" is an instruction. \$\endgroup\$ Aug 13 '20 at 17:38
  • \$\begingroup\$ no, you are not trying to light a LED, you are trying to compile code ... what the code is supposed to do is irrelevant to the error you are seeing \$\endgroup\$
    – jsotola
    Aug 13 '20 at 18:51
1
\$\begingroup\$

The MPLABX v5.40 IDE still has a lot of problems.

The pic-as(v2.20) tool chain is a nightmare.

This is the code I could get to work:

    ;
    ; File:     main.S
    ; Target:   PIC10F206
    ; Author:   dan1138
    ; Date:     2020-08-14
    ; Compiler: pic-as(v2.20)
    ; IDE:      MPLABX v5.40
    ;
    ; Depends on files:
    ;   <InstallPathVaries>\xc8\v2.20\pic\include\xc.inc
    ;   <InstallPathVaries>\xc8\v2.20\pic\include\pic.inc
    ;   <InstallPathVaries>\xc8\v2.20\pic\include\pic_as_chip_select.inc
    ;   <InstallPathVaries>\xc8\v2.20\pic\include\proc\pic10f206.inc
    ;
    ; Description:
    ;
    ;   Example project for the PIC10F206 controller using the pic-as(v2.20) tool chain.
    ;
    ; Add this line in the project properties box "pic-as Global Options -> Additional options": 
    ;
    ;   -Wa,-a -Wl,-pStartCode=0h,-pOscCalVec=1ffh
    ;
        PROCESSOR   10F206
        PAGEWIDTH   132
        RADIX       dec
    ;
    ; Include target specific definitions for special function registers
    ;
    #include <xc.inc>
    ;
    ; Set the configuration word
    ;
     config MCLRE = OFF, CP = OFF, WDTE = ON
    ;
    ;
    ;
    #define LED_GPIO    1
    ;
    ; Declare one byte in RAM
    ;
        PSECT   MainData,global,class=RAM,space=1,delta=1,noexec
        global  Counter
    Counter:    DS      1
    ;
    ; Simple test application that toggles
    ; GPIO bit x on every wake from sleep.
    ;
    ; The WDT timeout is at least 1280 milliseconds
    ; and at most 3968 milliseconds, will typically 
    ; be about 2300 milliseconds. It depends on the
    ; temperature and the VDD voltage.
    ;
        PSECT   StartCode,class=CODE,delta=2
        global  Start
    Start:
        btfss   STATUS,STATUS_nPD_POSITION
        btfsc   STATUS,STATUS_nTO_POSITION
        clrf    Counter
        movlw   0xDF                        ; Use FOSC/4 as TIMER0 clock not GPIO2
        option
        clrf    CMCON0                      ; turn off comparator
        bcf     OSCCAL,OSCCAL_FOSC4_POSITION; Do not drive GPIO2 with FOSC/4
        movlw   ~(1<<LED_GPIO)
        tris    GPIO
        andwf   GPIO,F                      ; set all output bits to zero

        movlw   (1<<LED_GPIO)
        btfsc   Counter,0
        xorwf   GPIO,F                      ; Turn on LED
        incf    Counter,F                   ; Increment the Counter value
        movf    GPIO,W
        sleep                               ; Wake from sleep results in a reset
        nop
    ;
    Loop:
        goto    Loop                        ; Hang here waiting for a reset
    ;
    ; In the PIC10F206 the factory calibration for
    ; the onchip oscillator is stored as a MOVLW 0xnn
    ; opcode as the last instruction of code space.
    ; On RESET the PC is set to all ones and this
    ; opcode is executed, then the PC rolls over
    ; to zero and the first opcode of the application
    ; will execute.
    ;
        PSECT   OscCalVec,class=CODE,delta=2
        global  OscCal
    OscCal:


        end     OscCal
\$\endgroup\$
3
  • \$\begingroup\$ It works. The output is a blinking LED on GP1. But as you say it is not pretty and I would have never gotten to this solution. \$\endgroup\$ Aug 16 '20 at 15:00
  • \$\begingroup\$ @theerrormagnet, The code is more complex than needed just to blink an LED. My goal was to do something fun. Apart from blinking the LED this code uses the watchdog timer to wake the controller from sleep mode. Sleep for Microchip base line controllers is tricky and the PIC10F206 has several traps for new players as well. All of the GPIO pins are overloaded with functionality that must be turned off to use the pins for digital I/O. The MPLABX simulator has some additional traps this code avoids. Then there's the pic-as(v2.20) tool chain issues.(continued) \$\endgroup\$
    – Dan1138
    Aug 16 '20 at 19:32
  • \$\begingroup\$ @theerrormagnet, (continued) You were doomed before you started. Microchip should apologise to you for the grief caused. \$\endgroup\$
    – Dan1138
    Aug 16 '20 at 19:35
3
\$\begingroup\$

From the 10F206 data sheet:

The Output Driver Control register is loaded with the contents of the W register by executing the TRIS f instruction. A ‘1’ from a TRIS register bit puts the corresponding output driver in a High-Impedance mode.

Your program attempts to make GP1 an input, not an output.

In this particular processor, the register TRISGPIO has no address, so you cannot use a movwf f type instruction to set GPIO direction. You must use the specific instruction tris 6...it moves the contents of W register into TRISGPIO. Or tris GPIO might also write to the TRISGPIO register too, since a header file would likely #define GPIO 6.

About the LED...its anode would face the PIC's Vdd pin, cathode faces GP1. Add a series resistor - something in the 100 to 1000 ohm ballpark.
I used Microchip's MPLAB IDE 8.92 to assemble a corrected version of your program. It includes a nice single-step simulator that lets you see internal bits

   #include p10f206.inc                          ;registers, config bits defined here
        __config _CP_OFF & _MCLRE_OFF & _WDTE_OFF ;MPASM compatible
    ;---------------------------------    
        ORG 0x0000
        
   INIT:
      MOVLW b'11111101' ;make GP1 an output pin
      TRIS GPIO         ;move content of working reg to TRISGPIO
      MOVLW b'00001101' ;set GP1 output low so that the LED with pullup res. lights up
      MOVWF GPIO        ;move working reg to GPIO
     
      movlw 2           ;select GP1 pin for toggling
  
  LOOP:
      xorwf GPIO   ;toggle GP1 pin
      GOTO LOOP ;loop forever every 3us
    ;----------------------------------
        END ;needed to end the program

Note that other PIC processors do GPIO direction control in different ways. In others, the direction register does have an address, where you can movwf f .
This one is a bit of an oddity.

\$\endgroup\$
4
  • \$\begingroup\$ The weird thing is, at the moment the led lights up even without any code as long as it is attached to my PC. But when I disconnect the PICkit4 and connect a 5V power supply to the P10F206 the LED does not light anymore. \$\endgroup\$ Aug 14 '20 at 13:01
  • \$\begingroup\$ Your programmer uses that same pin (GP1) to write code to P10F206 - it should release that line once it is done. Perhaps not. Your test with the 5V supply is the one you should pay attention to, and debug. \$\endgroup\$
    – glen_geek
    Aug 14 '20 at 13:28
  • \$\begingroup\$ I think the LED was just lit because the GP1 (which is PGC) was set to pull-down resistor in the Project Properties. Now I have set it to pull-up resistor and it does not light anymore. And I could not make it light up with your code. \$\endgroup\$ Aug 14 '20 at 20:17
  • \$\begingroup\$ debugging:(1) Did the chip get programmed? (2)Does the chip execute (is its clock running? (3) is GP1 an output, and is it logic low? (4) is the LED good?. These chips default to having MCLR pin active (unless you force it to be internally tied high). Try tying MCLR pin to Vdd, just in case it is active. Your program is a good one to test assemble/program/run. I've changed the code so to toggle GP1 between "high" & "low" very quickly. \$\endgroup\$
    – glen_geek
    Aug 14 '20 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.