Pic12f675


Closed Thread
Results 1 to 3 of 3

Thread: Pic12f675

  1. #1
    Join Date
    Jul 2007
    Posts
    11

    Default Pic12f675

    At first, sorry if this is wrong place. I´m PICBASIC newbie and my English sucks.
    I´m writing some code, and they work as I expect most of the time.

    Folows the code:

    Code:
            Device 12F675
            Config CPD_OFF, CP_OFF, BODEN_OFF, MCLRE_OFF, PWRTE_ON, WDT_OFF, INTRC_OSC_NOCLKOUT
       		XTAL = 4
    		CMCON = 7 ' Desliga a função do comparador
    '  +--------------------------+		
    '1 |Vdd	                   Vss| 8
    '2 |GPIO.5         GPIO.0/ANS0| 7
    '3 |GPIO.4/ANS3    GPIO.1/ANS1| 6
    '4 |GPIO.3/MCLR    GPIO.2/ANS2| 5      
    '  +--------------------------+ 
    
    ' ANSEL register's bits
            Symbol ANS0 = ANSEL.0
            Symbol ANS1 = ANSEL.1
            Symbol ANS2 = ANSEL.2
            Symbol ANS3 = ANSEL.3
            Symbol ADCS0 = ANSEL.4		' ADC conversion clock select bit
            Symbol ADCS1 = ANSEL.5		' ADC conversion clock select bit        
            Symbol ADCS2 = ANSEL.6		' ADC conversion clock select bit   
    
    ' ADCON0 register's bits		
            Symbol ADFM = ADCON0.7
            Symbol VCFG = ADCON0.6
            Symbol CHS2 = ADCON0.4		' ADC channel select bit
    		Symbol CHS1 = ADCON0.3		' ADC channel select bit
    		Symbol CHS0 = ADCON0.2		' ADC channel select bit
    		Symbol GO_DONE = ADCON0.1	' ADC Conversion status/ plus enable conversion-bit
    		Symbol ADON = ADCON0.0		' ADC Enable bit: 1 = enabled, 0 = disabled.
    		
    		
    		
    		TRISIO = %001011 ' output (0) 
                             ' GPIO.3 é somente input (1) digital
                             ' input (1) 
    		ANSEL.0 = 1 ' ANS0 input analogic
    		ANSEL.1 = 1 ' ANS1 input analogic 
    		ANSEL.2 = 0 ' ANS2 input digital 
    		ANSEL.3 = 0 ' ANS3 input digital
    		
    		
    
    		SERIAL_BAUD = 9600	
    		RSOUT_PIN = GPIO.2
    		RSOUT_MODE = TRUE
    		RSOUT_PACE = 10
    		
    		
    		ADIN_Res 10
    		ADIN_TAD FRC
    		ADIN_STIME 50
    		
    		Symbol LANTERNA = GPIO.4   	' Alias PORTD to LEDS
        	Symbol FAROL = GPIO.5
    	
    		
    '-------[ASSIGN A VARIABLE FOR THE ADC RESULT]---------------------------
         
            Dim AD_RESULT as ADRESL.WORD	' Convert the ADRESL register into a WORD variable 		
            Dim mySet as Word
            Dim myAtual as Word
            Dim myCh AS BYTE
            
      
            VCFG = 0						' VREF is set to VDD of PICmicro
            ADFM = 1						' Right justify the ADC result
            
    
    		Delayms 500				' Wait for PICmicro to stabilise
    		LANTERNA = 0
    		FAROL = 0
    	
    
    Loop:   
            MyCh = 0
            Gosub Plota_ADC
            mySet = AD_result
            DelayMS 500
            myCh = 1
            gosub PLOTA_ADC
            myAtual = Ad_result
         
            
    
            if mySet <= myAtual then
               FAROL = 1     
            Else
                FAROL = 0
            end if
    
            DelayMS 500
            Goto Loop       		' Go back to loop and blink LED forever
    End
            
    PLOTA_ADC:
            WARNINGS = OFF
            BYTE_MATH = On                 ' Enable expression optimisation
            ADCON0 = ADCON0 | (myCh << 2)  ' Select the channel to read --> ADCON0 = ADCON0 | (nro. canal << 2 )
            BYTE_MATH = OFF				   ' Disable expression optimisation
            WARNINGS = On
            AD_RESULT = ADIN myCh          ' faz a leitura do canal myX
            RSOut At 1,1,"ADC CHANNEL ", DEC myCh, " ", Dec AD_Result, 13 ' Display the result serially
            Return
    My problem is when RSOut was processed, if the FAROL is HIGH they go down and the corresponding LED turn off.

    Can anyone help me?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by perides View Post
    At first, sorry if this is wrong place. I´m PICBASIC newbie and my English sucks.
    I´m writing some code, and they work as I expect most of the time.

    Can anyone help me?
    Wrong forum...
    Proton Basic (or whatever it is) <> PicBasicPro...as the top of this page says.

  3. #3
    Join Date
    Jul 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Again, sorry. Both Basics are very close to me.
    I´ll try to find help in correct place. May the administrator can erase my post.

Similar Threads

  1. PIC12F675 problem with port 5
    By NL2TTL in forum mel PIC BASIC
    Replies: 2
    Last Post: - 5th June 2009, 01:23
  2. SMS with pic12f675 using Serout
    By camilen in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th June 2008, 20:16
  3. SERIN with a PIC12F675
    By ewandeur in forum Serial
    Replies: 4
    Last Post: - 30th July 2007, 15:04
  4. PIC12F675 trouble
    By russman613 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th February 2006, 18:40
  5. Erratic PIC12F675 behavior
    By russman613 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th February 2006, 14:46

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts