CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with PIC10f222
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

Problem with PIC10f222
PostPosted: Tue Apr 27, 2010 7:40 am     Reply with quote

I am not able to program pic10f222. The code is properly compiled with zero warning and error. But I am not getting the desired results. All the pins except the Gnd remains high. Even toggling any pin doesn't work. Even I cannot make any output pin low. Here is the code. I am using ccs v4.088. Please help.
Code:

#include <10F222.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCPU                   //Master Clear Pull-up disabled
#FUSES IOSC4                    //INTOSC speed 4 MHz

#use delay(clock=4000000)

#include "C:\Documents and Settings\Administrator\My Documents\iotest\main.h"


void main()
{

   setup_adc_ports(NO_ANALOGS);
   //setup_adc(false);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

   // TODO: USER CODE!!
     while(true)
       {
         output_high(PIN_B0);
         delay_ms(50);
         output_low(PIN_B0);
         delay_ms(50);

       }
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 11:48 am     Reply with quote

What hardware are you using to program the PIC?
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 3:06 pm     Reply with quote

Try this program. It should blink an LED on pin B0.
Code:

#include <10F222.H>
#fuses IOSC4,NOWDT,NOMCLR
#use delay(clock=4000000)

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}

//=========================
void main()
{
set_options(0xDF);  // Enable pin B2 for normal i/o

setup_adc_ports(NO_ANALOGS);

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Apr 27, 2010 9:55 pm     Reply with quote

I am using ICD-2
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Apr 27, 2010 10:20 pm     Reply with quote

even trying set_options(value) code doesnt work. what to do please help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 11:10 pm     Reply with quote

I tested it with vs. 4.073, which is the free version of PCB that comes with
MPLAB 4.086. I used an ICD2 to program it.

What happens if you compile my test program, program the PIC, and
then use the ICD2 to do a Verify operation. Does it verify OK ?

After you finish programming the PIC, do you click on the "Release from
Reset" button in MPLAB ? This will allow the PIC to run. However, since
Pin B0 is also used by the ICD2 for ICSP Data, you should disconnect
the ICD2 from the 10F222 board in order to run the test.


If that doesn't help, then compile the program that I posted with your
version (v4.088), and post the .LST file.
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Apr 27, 2010 11:24 pm     Reply with quote

I tried to program. but the same result. Here is the list file
Code:

CCS PCB C Compiler, Version 4.084, 36728               28-Apr-10 10:54

               Filename: main.lst

               ROM used: 49 words (10%)
                         Largest free fragment is 463
               RAM used: 4 (17%) at main() level
                         5 (22%) worst case
               Stack:    1 locations

*
0000:  MOVWF  05
0001:  GOTO   015
0002:  GOTO   003
.................... #include "C:\Documents and Settings\Administrator\My Documents\iotest\main.h"
.................... #include <10F222.h>
.................... //////// Standard Header file for the PIC10F222 device ////////////////
.................... #device PIC10F222
.................... #list
.................... 
.................... #FUSES IOSC4                   //INTOSC speed 4MHz
.................... #device adc=8
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES MCLR                     //Master Clear pin enabled
.................... #FUSES NOPROTECT                //Code not protected from reading
.................... #FUSES NOMCPU                   //Master Clear Pull-up disabled
.................... 
.................... 
.................... #use delay(clock=4000000)
*
0003:  MOVF   0D,W
0004:  BTFSC  03.2
0005:  GOTO   014
0006:  MOVLW  01
0007:  MOVWF  0A
0008:  CLRF   09
0009:  DECFSZ 09,F
000A:  GOTO   009
000B:  DECFSZ 0A,F
000C:  GOTO   008
000D:  MOVLW  4A
000E:  MOVWF  09
000F:  DECFSZ 09,F
0010:  GOTO   00F
0011:  GOTO   012
0012:  DECFSZ 0D,F
0013:  GOTO   006
0014:  RETLW  00
.................... 
.................... 
.................... 
....................                       
.................... /*
.................... #byte MCU_INDF = 0x000
.................... #byte MCU_TMR0 = 0x001
.................... #byte MCU_PCL = 0x002
.................... #byte MCU_STATUS = 0x003
.................... #bit    MCU_DC = MCU_STATUS.1
.................... #bit    MCU_PD = MCU_STATUS.3
.................... #bit    MCU_TO = MCU_STATUS.4
.................... #bit    MCU_GPWUF = MCU_STATUS.7
.................... #byte MCU_FSR = 0x004
.................... #byte MCU_OSCCAL = 0x005
.................... #bit    MCU_FOSC4 = MCU_OSCCAL.0
.................... #bit    MCU_CAL0 = MCU_OSCCAL.1
.................... #bit    MCU_CAL1 = MCU_OSCCAL.2
.................... #bit    MCU_CAL2 = MCU_OSCCAL.3
.................... #bit    MCU_CAL3 = MCU_OSCCAL.4
.................... #bit    MCU_CAL4 = MCU_OSCCAL.5
.................... #bit    MCU_CAL5 = MCU_OSCCAL.6
.................... #bit    MCU_CAL6 = MCU_OSCCAL.7
.................... #byte MCU_GPIO = 0x006
.................... #bit    MCU_GPIO0 = MCU_GPIO.0
.................... #bit    MCU_GPIO1 = MCU_GPIO.1
.................... #bit    MCU_GPIO2 = MCU_GPIO.2
.................... #bit    MCU_GPIO3 = MCU_GPIO.3
.................... #byte MCU_ADCON0 = 0x007
.................... #bit    MCU_ADON = MCU_ADCON0.0
.................... #bit    MCU_GO = MCU_ADCON0.1
.................... #bit    MCU_CHS0 = MCU_ADCON0.2
.................... #bit    MCU_CHS1 = MCU_ADCON0.3
.................... #bit    MCU_ANS0 = MCU_ADCON0.6
.................... #bit    MCU_ANS1 = MCU_ADCON0.7
.................... #byte MCU_ADRES = 0x008
.................... 
.................... 
.................... */
.................... 
.................... 
.................... #define set_options(value){#ASM    \
....................                      MOVLW value   \
....................                       OPTION        \
....................                      #ENDASM}
.................... 
....................            void main()
....................              {
0015:  CLRF   04
....................            set_options(0xDF);
*
0018:  MOVLW  DF
0019:  OPTION
....................    setup_adc_ports(NO_ANALOGS);
001A:  BCF    07.6
001B:  BCF    07.7
....................   
....................    // TODO: USER CODE!!
.................... 
....................         while(true)
....................              {
....................               output_high(PIN_B0);
001C:  BCF    0B.0
001D:  MOVF   0B,W
001E:  TRIS   6
001F:  BSF    06.0
....................               
....................                 delay_ms(500);
0020:  MOVLW  02
0021:  MOVWF  0C
0022:  MOVLW  FA
0023:  MOVWF  0D
0024:  CALL   003
0025:  DECFSZ 0C,F
0026:  GOTO   022
....................             output_low(PIN_B0);
0027:  BCF    0B.0
0028:  MOVF   0B,W
0029:  TRIS   6
002A:  BCF    06.0
....................               
....................              delay_ms(500);
002B:  MOVLW  02
002C:  MOVWF  0C
002D:  MOVLW  FA
002E:  MOVWF  0D
002F:  CALL   003
0030:  DECFSZ 0C,F
0031:  GOTO   02D
....................              } 
0032:  GOTO   01C
.................... 
.................... }
0033:  SLEEP

Configuration Fuses:
   Word  1: 0FFA   MCLR NOPROTECT NOWDT NOMCPU IOSC4
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 27, 2010 11:48 pm     Reply with quote

I notice you changed the #fuses to enable MCLR. Do you have a 10K
resistor on the MCLR pin ? You need one.

The symptoms you described would possibly occur if the PIC was held
in reset. With MCLR enabled, I wonder if you're missing the 10K pull-up
on the MCLR pin ?
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 12:20 am     Reply with quote

I have changed the code . This is the new lst file.Even then it is not working.
I have also replaced the IC.and checked.Everytime all the pins except GND(Pin no2) shows high. I tried the same code of reading analog from pot and changing output in PIC12F675. It is working fine. I am not able to figure out why the code is not working with pic10f222.


Code:
CCS PCB C Compiler, Version 4.084, 36728               28-Apr-10 11:46

               Filename: main.lst

               ROM used: 49 words (10%)
                         Largest free fragment is 463
               RAM used: 4 (17%) at main() level
                         5 (22%) worst case
               Stack:    1 locations

*
0000:  MOVWF  05
0001:  GOTO   015
0002:  GOTO   003
.................... #include "C:\Documents and Settings\Administrator\My Documents\iotest\main.h"
.................... #include <10F222.h>
.................... //////// Standard Header file for the PIC10F222 device ////////////////
.................... #device PIC10F222
.................... #list
.................... 
.................... #device adc=8
.................... 
.................... #FUSES NOWDT                    //No Watch Dog Timer
.................... #FUSES NOMCLR                   //Master Clear pin used for I/O
.................... #FUSES NOPROTECT                //Code not protected from reading
.................... #FUSES NOMCPU                   //Master Clear Pull-up disabled
.................... #FUSES IOSC4                    //INTOSC speed 4 MHz
.................... 
.................... #use delay(clock=4000000)
*
0003:  MOVF   0D,W
0004:  BTFSC  03.2
0005:  GOTO   014
0006:  MOVLW  01
0007:  MOVWF  0A
0008:  CLRF   09
0009:  DECFSZ 09,F
000A:  GOTO   009
000B:  DECFSZ 0A,F
000C:  GOTO   008
000D:  MOVLW  4A
000E:  MOVWF  09
000F:  DECFSZ 09,F
0010:  GOTO   00F
0011:  GOTO   012
0012:  DECFSZ 0D,F
0013:  GOTO   006
0014:  RETLW  00
.................... 
.................... 
.................... 
.................... #define set_options(value)   {#ASM         \ 
....................                               MOVLW  value \ 
....................                               OPTION       \ 
....................                               #ENDASM} 
.................... 
.................... void main()
.................... {
0015:  CLRF   04
.................... set_options(0xDF);  // Enable pin B2 for normal i/o 
*
0018:  MOVLW  DF
0019:  OPTION
....................    setup_adc_ports(NO_ANALOGS);
001A:  BCF    07.6
001B:  BCF    07.7
....................    // TODO: USER CODE!! 
....................      while(true)
....................          {
....................     output_high(PIN_B0);
001C:  BCF    0B.0
001D:  MOVF   0B,W
001E:  TRIS   6
001F:  BSF    06.0
.................... 
....................       delay_ms(500);
0020:  MOVLW  02
0021:  MOVWF  0C
0022:  MOVLW  FA
0023:  MOVWF  0D
0024:  CALL   003
0025:  DECFSZ 0C,F
0026:  GOTO   022
....................         output_low(PIN_B0);
0027:  BCF    0B.0
0028:  MOVF   0B,W
0029:  TRIS   6
002A:  BCF    06.0
....................     
....................     delay_ms(500);
002B:  MOVLW  02
002C:  MOVWF  0C
002D:  MOVLW  FA
002E:  MOVWF  0D
002F:  CALL   003
0030:  DECFSZ 0C,F
0031:  GOTO   02D
....................           }
0032:  GOTO   01C
.................... 
.................... }
0033:  SLEEP

Configuration Fuses:
   Word  1: 0FEA   NOMCLR NOPROTECT NOWDT NOMCPU IOSC4
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 28, 2010 12:29 am     Reply with quote

What is the Vdd voltage on the PIC ?
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 12:40 am     Reply with quote

5.05V output from 7805. The IC is PIC10F222 E/OT 6-pin sot-23
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 1:04 am     Reply with quote

Sir,
can you send a hex file for the program you build which toggles LED at pin 1. email id - spradecom.rnd@gmail.com

If your hex works then there is problem in the compiler or our hardware set up. If your HEX doesnt work then our ICs are faulty
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 1:16 am     Reply with quote

thank you very much sir, now changing ic and removing holding from reset worked
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 1:59 am     Reply with quote

Sir,
we are assigning AN0 as a analog input. But it always remains high. Is it that the ICSPDAT pin is continuous high. What steps to do to work pin no 1 as analog input after programming ?

Code:

#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCPU                   //Master Clear Pull-up disabled
#FUSES IOSC4                    //INTOSC speed 4 MHz

#use delay(clock=4000000)

unsigned int8 value ;

void main()
{

   setup_adc_ports(sAN0);
   setup_adc(true);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

   // TODO: USER CODE!!
   
    while(true)
     {


      set_adc_channel(0);
     delay_ms(10);
    //       
           value = Read_ADC();
               output_high(PIN_B2);
              delay_ms(value);
              output_low(PIN_B2);
              delay_ms(255-value);
          }

}
spradecom.rnd



Joined: 27 Apr 2010
Posts: 16
Location: Mumbai

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 28, 2010 5:31 am     Reply with quote

The ADC value always remains high even if not input is given. the Pin shows zero voltage. then how the value in ADRESH is always high
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group