EmbeddedRelated.com
Forums

UART setup for 801C188EB/80186

Started by srao October 14, 2015
On 10/17/2015 7:42 AM, Simon Clubley wrote:
> On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >> On 10/16/2015 7:33 PM, srao wrote: >>>> Did something like this:- >>>> >>>> while(1) >>>> { >>>> >>>> for (N loops) //togggle watchdog >>>> { >>>> //port1 clear bits >>>> Set bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> >>>> for (N loops) >>>> { >>>> //port1 clear bits >>>> //Clear bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> --------------------------------------- >>> not sure if I am doing something wrong here. the above code does not >>> toggle the Port pin. is there a better way to solve this? >> >> Where do you change the value written to the port? You don't even show >> where you set the value of 'a' initially. >> > > The OP _really_ needs to show us _actual_ code not the above pseudo code. > > Also, the above sequence "feels" really wrong to me. Why is the port > pin being set N times and then cleared N times ? > > With a watchdog you are supposed to send a specific sequence _once_ > every time you decide to report that you are still alive and not stuck.
I'm guessing this is test code to get the durn thing to work without resetting. I get that. But he needs to show his code. -- Rick
On Sat, 17 Oct 2015 11:42:34 +0000 (UTC), Simon Clubley
<clubley@remove_me.eisner.decus.org-Earth.UFP> wrote:

>On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >> On 10/16/2015 7:33 PM, srao wrote: >>>> Did something like this:- >>>> >>>> while(1) >>>> { >>>> >>>> for (N loops) //togggle watchdog >>>> { >>>> //port1 clear bits >>>> Set bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> >>>> for (N loops) >>>> { >>>> //port1 clear bits >>>> //Clear bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> --------------------------------------- >>> not sure if I am doing something wrong here. the above code does not >>> toggle the Port pin. is there a better way to solve this? >> >> Where do you change the value written to the port? You don't even show >> where you set the value of 'a' initially. >> > >The OP _really_ needs to show us _actual_ code not the above pseudo code.
After following the discussion, it appears that the original code has never existed. :-)
On 15.10.15 03:44, srao wrote:
> I am having some trouble setting up UART for a 80188 processor. Could > someone please point me in the right direction. I think I am making the > simple program more complicated. > the 16 Mega hz freq is configured to baud 9600.
I had to dig up some backups from a quarter century ago ... Here is a test that has been run in 1990, compiled with Borland C: ---- clip clip ---- /* TEST.C - Serial output test */ /* Compiler controls for Borland C++ v. 2 */ #pragma option -ms /* small addressing */ #pragma option -1 /* 80186 family processor */ #pragma option -a- /* pack structures tightly */ #pragma option -b- /* short enums */ #pragma option -d /* do not duplicate strings */ #pragma option -f- /* no floating point */ #ifdef _DEBUG #pragma option -v /* add symbols to code */ #else #pragma option -G /* optimize code speed */ #pragma option -O /* optimize code */ #pragma option -Z /* optimize pointers */ #pragma option -k- /* no need for normal stack frame */ #endif #define CPUCLK 16000000L /* CPU clock: 16 MHz */ /* 80186EB hardware registers */ #define CPUIO 0xff00 /* CPU I/O address base */ #define B0CMP (CPUIO + 0x60) /* serial 0 baud compare */ #define S0CON (CPUIO + 0x64) /* serial 0 control */ #define S0STS (CPUIO + 0x66) /* serial 0 status */ #define S0TBUF (CPUIO + 0x6a) /* serial 0 transmit buffer */ #define ICLK (1 << 15) /* B0CMP: internal clock bit */ #define TXE (1 << 3) /* S0STS: transmitter empty */ #define BAUD 9600 /* baud rate */ #define BCVAL ((CPUCLK / 8)/ BAUD - 1) /* baud compare value */ #define SCVAL 0x01 /* S0CON: no parity, no rx, mode 1 */ /* Initialize serial I/O */ static void serinit(void) { outport(B0CMP, ICLK | BCVAL); outport(S0CON, SCVAL); } /* Send a byte out */ static void putch(unsigned char ch) { while (!(inport(S0STS) & TXE)) ; outport(S0TBUF, ch); } /* Send a string out */ static void putstr(char *str) { for (; *str; str++) putch(*str); } /* MAIN PROGRAM */ void main(void) { serinit(); for (;;) putstr("Hello, world!\r\n"); } ---- clip clip ---- Please note that the Borland outport() functions are 16 bit wide. The CPU I/O registers cannot be accessed with 8 bit instructions. -- -TV
>On 15.10.15 03:44, srao wrote: >> I am having some trouble setting up UART for a 80188 processor. Could >> someone please point me in the right direction. I think I am making
the
>> simple program more complicated. >> the 16 Mega hz freq is configured to baud 9600. > >I had to dig up some backups from a quarter century ago ... > >Here is a test that has been run in 1990, compiled with Borland C: > >---- clip clip ---- > >/* TEST.C - Serial output test */ > >/* Compiler controls for Borland C++ v. 2 */ > >#pragma option -ms /* small addressing */ >#pragma option -1 /* 80186 family processor */ >#pragma option -a- /* pack structures tightly */ >#pragma option -b- /* short enums */ >#pragma option -d /* do not duplicate strings */ >#pragma option -f- /* no floating point */ > >#ifdef _DEBUG >#pragma option -v /* add symbols to code */ >#else >#pragma option -G /* optimize code speed */ >#pragma option -O /* optimize code */ >#pragma option -Z /* optimize pointers */ >#pragma option -k- /* no need for normal stack frame */ >#endif > >#define CPUCLK 16000000L /* CPU clock: 16 MHz */ > >/* 80186EB hardware registers */ > >#define CPUIO 0xff00 /* CPU I/O address base */ >#define B0CMP (CPUIO + 0x60) /* serial 0 baud compare */ >#define S0CON (CPUIO + 0x64) /* serial 0 control */ >#define S0STS (CPUIO + 0x66) /* serial 0 status */ >#define S0TBUF (CPUIO + 0x6a) /* serial 0 transmit buffer */ > >#define ICLK (1 << 15) /* B0CMP: internal clock bit */ >#define TXE (1 << 3) /* S0STS: transmitter empty */ > >#define BAUD 9600 /* baud rate */ >#define BCVAL ((CPUCLK / 8)/ BAUD - 1) /* baud compare value */ >#define SCVAL 0x01 /* S0CON: no parity, no rx, >mode 1 */ > > >/* Initialize serial I/O */ > >static void serinit(void) > { > outport(B0CMP, ICLK | BCVAL); > outport(S0CON, SCVAL); > } > > >/* Send a byte out */ > >static void putch(unsigned char ch) > { > while (!(inport(S0STS) & TXE)) > ; > > outport(S0TBUF, ch); > } > > >/* Send a string out */ > >static void putstr(char *str) > { > for (; *str; str++) > putch(*str); > } > > >/* MAIN PROGRAM */ > >void main(void) > { > serinit(); > > for (;;) > putstr("Hello, world!n"); > } > >---- clip clip ---- > >Please note that the Borland outport() functions are 16 bit wide. >The CPU I/O registers cannot be accessed with 8 bit instructions. > >-- > >-TV
Thanks a lot for your input Tauno Voipio. Im sure this would help identify whats going wrong with my method. really appreciate you searching for it, as I have never worked with this processor before, this is a very good pointer and a start --------------------------------------- Posted through http://www.EmbeddedRelated.com
>On 10/17/2015 7:42 AM, Simon Clubley wrote: >> On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >>> On 10/16/2015 7:33 PM, srao wrote: >>>>> Did something like this:- >>>>> >>>>> while(1) >>>>> { >>>>> >>>>> for (N loops) //togggle watchdog >>>>> { >>>>> //port1 clear bits >>>>> Set bit on watchdog PIN >>>>> outport(0x00xx,a); >>>>> } >>>>> >>>>> for (N loops) >>>>> { >>>>> //port1 clear bits >>>>> //Clear bit on watchdog PIN >>>>> outport(0x00xx,a); >>>>> } >>>>> --------------------------------------- >>>> not sure if I am doing something wrong here. the above code does not >>>> toggle the Port pin. is there a better way to solve this? >>> >>> Where do you change the value written to the port? You don't even
show
>>> where you set the value of 'a' initially. >>> >> >> The OP _really_ needs to show us _actual_ code not the above pseudo
code.
>> >> Also, the above sequence "feels" really wrong to me. Why is the port >> pin being set N times and then cleared N times ? >> >> With a watchdog you are supposed to send a specific sequence _once_ >> every time you decide to report that you are still alive and not
stuck.
> >I'm guessing this is test code to get the durn thing to work without >resetting. I get that. But he needs to show his code. > >-- > >Rick
Hi Rick, I will post the complete code soon. As far as i read the data sheet, the watchdog (hardware) is connected to one of the ooutput pins and I am just trying to continously write 0 or 1 to this port to not allow it to kick the watchdog timer and reset the pin. I did not find a mention of a specific sequence to be set to stop the watchdog from kicking. Will post source code soon. --------------------------------------- Posted through http://www.EmbeddedRelated.com
>On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >> On 10/16/2015 7:33 PM, srao wrote: >>>> Did something like this:- >>>> >>>> while(1) >>>> { >>>> >>>> for (N loops) //togggle watchdog >>>> { >>>> //port1 clear bits >>>> Set bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> >>>> for (N loops) >>>> { >>>> //port1 clear bits >>>> //Clear bit on watchdog PIN >>>> outport(0x00xx,a); >>>> } >>>> --------------------------------------- >>> not sure if I am doing something wrong here. the above code does not >>> toggle the Port pin. is there a better way to solve this? >> >> Where do you change the value written to the port? You don't even show
>> where you set the value of 'a' initially. >> > >The OP _really_ needs to show us _actual_ code not the above pseudo
code.
> >Also, the above sequence "feels" really wrong to me. Why is the port >pin being set N times and then cleared N times ? > >With a watchdog you are supposed to send a specific sequence _once_ >every time you decide to report that you are still alive and not stuck. > >Simon. >Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP >Microsoft: Bringing you 1980s technology to a 21st century world
The exact source code is as below. This lies within main() while(1) { for (i=0;i<2000;i++) { int p1dir=inport(0x0050); //clear PD5 bit PXDIR register p1dir &= ~(1 << 5); int p1con=inport(0x0054); //clear PC5 bit in PXCON register p1con &= ~(1 << 5); int b=0x20; //toggle watchdog int a=inport(0x0056); a&=~b; outport(0x0056,a); } for (i=0;i<2000;i++) { int p1dir=inport(0x0050); //clear PD5 bit PXDIR register p1dir &= ~(1 << 5); int p1con=inport(0x0054); //clear PC5 bit in PXCON register p1con &= ~(1 << 5); int b=0x20; int a=inport(0x0056); a|=~b; outport(0x0056,a); } --------------------------------------- Posted through http://www.EmbeddedRelated.com
On 20/10/15 00:22, srao wrote:
>> On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >>> On 10/16/2015 7:33 PM, srao wrote: >>>>> Did something like this:- >>>>> >>>>> while(1) >>>>> { >>>>> >>>>> for (N loops) //togggle watchdog >>>>> { >>>>> //port1 clear bits >>>>> Set bit on watchdog PIN >>>>> outport(0x00xx,a); >>>>> } >>>>> >>>>> for (N loops) >>>>> { >>>>> //port1 clear bits >>>>> //Clear bit on watchdog PIN >>>>> outport(0x00xx,a); >>>>> } >>>>> --------------------------------------- >>>> not sure if I am doing something wrong here. the above code does not >>>> toggle the Port pin. is there a better way to solve this? >>> >>> Where do you change the value written to the port? You don't even show > >>> where you set the value of 'a' initially. >>> >> >> The OP _really_ needs to show us _actual_ code not the above pseudo > code. >> >> Also, the above sequence "feels" really wrong to me. Why is the port >> pin being set N times and then cleared N times ? >> >> With a watchdog you are supposed to send a specific sequence _once_ >> every time you decide to report that you are still alive and not stuck. >> >> Simon. >> Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP >> Microsoft: Bringing you 1980s technology to a 21st century world > > > > The exact source code is as below. This lies within main() > > > while(1) > { > > for (i=0;i<2000;i++) > { > int p1dir=inport(0x0050); //clear PD5 bit PXDIR register > p1dir &= ~(1 << 5); > > int p1con=inport(0x0054); //clear PC5 bit in PXCON > register > p1con &= ~(1 << 5); > > int b=0x20; //toggle watchdog > int a=inport(0x0056); > a&=~b; > outport(0x0056,a); > } > > for (i=0;i<2000;i++) > { > int p1dir=inport(0x0050); //clear PD5 bit PXDIR register > p1dir &= ~(1 << 5); > > int p1con=inport(0x0054); //clear PC5 bit in PXCON > register > p1con &= ~(1 << 5); > > > int b=0x20; > int a=inport(0x0056); > a|=~b; > outport(0x0056,a); > } >
I'm having difficulty trying to figure out what you are trying to do, but I can tell you that no matter what you /think/ you are doing, your code is /badly/ wrong. It is wrong in a way that indicates you have no idea what you are doing. (This is constructive criticism aimed at helping you where you need it most - I am not trying to be insulting.) It is time to take a step back, and look at the big picture here. What are you trying to achieve, and why are you doing it? If you are trying to learn about embedded programming, you are going about it the wrong way - pick a modern, friendly microcontroller and a decent book (ask here for advice if you like). If you are doing this professionally, then it can only be in the context of maintaining an ancient system. Without a larger context, it is impossible to judge whether something this old /should/ be maintained, or whether it would be better to replace it. But it is clear that you are not qualified for the job - the sooner you accept that and arrange for a qualified person to handle it, the better for everyone (especially you). If there is no other possibility than for /you/ to do the programming here, then at least hire a consultant for a few days to work with you and show you some of the basics. If you have a strong enough background in programming or electronics, that might be enough to give you a chance.
>On 20/10/15 00:22, srao wrote: >>> On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >>>> On 10/16/2015 7:33 PM, srao wrote: >>>>>> Did something like this:- >>>>>> >>>>>> while(1) >>>>>> { >>>>>> >>>>>> for (N loops) //togggle watchdog >>>>>> { >>>>>> //port1 clear bits >>>>>> Set bit on watchdog PIN >>>>>> outport(0x00xx,a); >>>>>> } >>>>>> >>>>>> for (N loops) >>>>>> { >>>>>> //port1 clear bits >>>>>> //Clear bit on watchdog PIN >>>>>> outport(0x00xx,a); >>>>>> } >>>>>> --------------------------------------- >>>>> not sure if I am doing something wrong here. the above code does
not
>>>>> toggle the Port pin. is there a better way to solve this? >>>> >>>> Where do you change the value written to the port? You don't even
show
>> >>>> where you set the value of 'a' initially. >>>> >>> >>> The OP _really_ needs to show us _actual_ code not the above pseudo >> code. >>> >>> Also, the above sequence "feels" really wrong to me. Why is the port >>> pin being set N times and then cleared N times ? >>> >>> With a watchdog you are supposed to send a specific sequence _once_ >>> every time you decide to report that you are still alive and not
stuck.
>>> >>> Simon. >>> Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP >>> Microsoft: Bringing you 1980s technology to a 21st century world >> >> >> >> The exact source code is as below. This lies within main() >> >> >> while(1) >> { >> >> for (i=0;i<2000;i++) >> { >> int p1dir=inport(0x0050); //clear PD5 bit PXDIR
register
>> p1dir &= ~(1 << 5); >> >> int p1con=inport(0x0054); //clear PC5 bit in PXCON >> register >> p1con &= ~(1 << 5); >> >> int b=0x20; //toggle watchdog >> int a=inport(0x0056); >> a&=~b; >> outport(0x0056,a); >> } >> >> for (i=0;i<2000;i++) >> { >> int p1dir=inport(0x0050); //clear PD5 bit PXDIR
register
>> p1dir &= ~(1 << 5); >> >> int p1con=inport(0x0054); //clear PC5 bit in PXCON >> register >> p1con &= ~(1 << 5); >> >> >> int b=0x20; >> int a=inport(0x0056); >> a|=~b; >> outport(0x0056,a); >> } >> > >I'm having difficulty trying to figure out what you are trying to do, >but I can tell you that no matter what you /think/ you are doing, your >code is /badly/ wrong. It is wrong in a way that indicates you have no >idea what you are doing. (This is constructive criticism aimed at >helping you where you need it most - I am not trying to be insulting.) > >It is time to take a step back, and look at the big picture here. What >are you trying to achieve, and why are you doing it? > >If you are trying to learn about embedded programming, you are going >about it the wrong way - pick a modern, friendly microcontroller and a >decent book (ask here for advice if you like). > >If you are doing this professionally, then it can only be in the context >of maintaining an ancient system. Without a larger context, it is >impossible to judge whether something this old /should/ be maintained, >or whether it would be better to replace it. But it is clear that you >are not qualified for the job - the sooner you accept that and arrange >for a qualified person to handle it, the better for everyone (especially >you). > > >If there is no other possibility than for /you/ to do the programming >here, then at least hire a consultant for a few days to work with you >and show you some of the basics. If you have a strong enough background >in programming or electronics, that might be enough to give you a
chance. I know sometimes its hard to understand a question. Everyone has the right to learn on their own and I am doing my part. These are two simple basic programs for UART configuration and watchdog kick. I was new with this kind of processor as its an old one and never had to deal with a watchdog scenario, I just posted my questions as I was unfamiliar with the environment and as I had only worked with PICS and IAR's. Sorry for the trouble you had. --------------------------------------- Posted through http://www.EmbeddedRelated.com
On 20/10/15 18:25, srao wrote:
>> On 20/10/15 00:22, srao wrote:
>> I'm having difficulty trying to figure out what you are trying to do, >> but I can tell you that no matter what you /think/ you are doing, your >> code is /badly/ wrong. It is wrong in a way that indicates you have no >> idea what you are doing. (This is constructive criticism aimed at >> helping you where you need it most - I am not trying to be insulting.) >> >> It is time to take a step back, and look at the big picture here. What >> are you trying to achieve, and why are you doing it? >> >> If you are trying to learn about embedded programming, you are going >> about it the wrong way - pick a modern, friendly microcontroller and a >> decent book (ask here for advice if you like). >> >> If you are doing this professionally, then it can only be in the context >> of maintaining an ancient system. Without a larger context, it is >> impossible to judge whether something this old /should/ be maintained, >> or whether it would be better to replace it. But it is clear that you >> are not qualified for the job - the sooner you accept that and arrange >> for a qualified person to handle it, the better for everyone (especially >> you). >> >> >> If there is no other possibility than for /you/ to do the programming >> here, then at least hire a consultant for a few days to work with you >> and show you some of the basics. If you have a strong enough background >> in programming or electronics, that might be enough to give you a > chance. > > I know sometimes its hard to understand a question. Everyone has the right > to learn on their own and I am doing my part. > > These are two simple basic programs for UART configuration and watchdog > kick. I was new with this kind of processor as its an old one and never > had to deal with a watchdog scenario, I just posted my questions as I was > unfamiliar with the environment and as I had only worked with PICS and > IAR's. Sorry for the trouble you had.
Could you please tell us if you are doing this as a job, or as a hobby? And if it is a job, what is the scope, and why are you doing it? From your posts so far, you are going to need guiding and help with a great deal of work because you don't understand what you are doing - your problems are much bigger than UART configuration or watchdogs. If we know what you are trying to achieve here, we can give better advice. That advice might be in showing you how to clear a bit in a port - but it might also be advice on a book to read, suggestions for replacing the microcontroller and toolchain, or simply to hire an experienced developer for the job. Clearly the advice will be very different if this is paid work or home study. People in this group, myself included, are very happy to encourage people to learn about embedded development. We are a good deal less keen on helping someone do a professional job for which they are not qualified. (Well, there are some people here ready to do that - but they will want paid for their consultancy!)
On 2015-10-20 srao wrote in comp.arch.embedded:
>>On 20/10/15 00:22, srao wrote: >>>> On 2015-10-17, rickman <gnuarm@gmail.com> wrote: >>>>> On 10/16/2015 7:33 PM, srao wrote: >>>>>>> Did something like this:- >>>>>>> >>>>>>> while(1) >>>>>>> { >>>>>>> >>>>>>> for (N loops) //togggle watchdog >>>>>>> { >>>>>>> //port1 clear bits >>>>>>> Set bit on watchdog PIN >>>>>>> outport(0x00xx,a); >>>>>>> } >>>>>>> >>>>>>> for (N loops) >>>>>>> { >>>>>>> //port1 clear bits >>>>>>> //Clear bit on watchdog PIN >>>>>>> outport(0x00xx,a); >>>>>>> } >>>>>>> --------------------------------------- >>>>>> not sure if I am doing something wrong here. the above code does > not >>>>>> toggle the Port pin. is there a better way to solve this? >>>>> >>>>> Where do you change the value written to the port? You don't even > show >>> >>>>> where you set the value of 'a' initially. >>>>> >>>> >>>> The OP _really_ needs to show us _actual_ code not the above pseudo >>> code. >>>> >>>> Also, the above sequence "feels" really wrong to me. Why is the port >>>> pin being set N times and then cleared N times ? >>>> >>>> With a watchdog you are supposed to send a specific sequence _once_ >>>> every time you decide to report that you are still alive and not > stuck. >>>> >>>> Simon. >>>> Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP >>>> Microsoft: Bringing you 1980s technology to a 21st century world >>> >>> >>> >>> The exact source code is as below. This lies within main() >>> >>> >>> while(1) >>> { >>> >>> for (i=0;i<2000;i++) >>> { >>> int p1dir=inport(0x0050); //clear PD5 bit PXDIR register >>> p1dir &= ~(1 << 5); >>> >>> int p1con=inport(0x0054); //clear PC5 bit in PXCON register >>> p1con &= ~(1 << 5); >>> >>> int b=0x20; //toggle watchdog >>> int a=inport(0x0056); >>> a&=~b; >>> outport(0x0056,a); >>> } >>> >>> for (i=0;i<2000;i++) >>> { >>> int p1dir=inport(0x0050); //clear PD5 bit PXDIR register >>> p1dir &= ~(1 << 5); >>> >>> int p1con=inport(0x0054); //clear PC5 bit in PXCON register >>> p1con &= ~(1 << 5); >>> >>> >>> int b=0x20; >>> int a=inport(0x0056); >>> a|=~b; >>> outport(0x0056,a); >>> } >>> >> >>I'm having difficulty trying to figure out what you are trying to do, >>but I can tell you that no matter what you /think/ you are doing, your >>code is /badly/ wrong. It is wrong in a way that indicates you have no >>idea what you are doing. (This is constructive criticism aimed at >>helping you where you need it most - I am not trying to be insulting.) >> >>It is time to take a step back, and look at the big picture here. What >>are you trying to achieve, and why are you doing it? >> >>If you are trying to learn about embedded programming, you are going >>about it the wrong way - pick a modern, friendly microcontroller and a >>decent book (ask here for advice if you like). >> >>If you are doing this professionally, then it can only be in the context >>of maintaining an ancient system. Without a larger context, it is >>impossible to judge whether something this old /should/ be maintained, >>or whether it would be better to replace it. But it is clear that you >>are not qualified for the job - the sooner you accept that and arrange >>for a qualified person to handle it, the better for everyone (especially >>you). >> >> >>If there is no other possibility than for /you/ to do the programming >>here, then at least hire a consultant for a few days to work with you >>and show you some of the basics. If you have a strong enough background >>in programming or electronics, that might be enough to give you a > chance. > > I know sometimes its hard to understand a question. Everyone has the right > to learn on their own and I am doing my part. > > These are two simple basic programs for UART configuration and watchdog > kick. I was new with this kind of processor as its an old one and never > had to deal with a watchdog scenario, I just posted my questions as I was > unfamiliar with the environment and as I had only worked with PICS and > IAR's. Sorry for the trouble you had.
As Rick already said, it is unclear what you are trying to achieve with the above code. The code shows a lack of knowledge on C programming and on basic processor operating principles. This is OK if you are just learning, but if this is a job... So please tell us what context this is in. I do know some PICs (ouch, long time ago), but have never heard of IAR's. How do you expect to clear a bit in the registers with the above code? Why do you need to repeat this 2000 times? If you wanted to do this on a PIC, how would you do it? IIRC on a PIC you always had to load stuff into the W register before you could do anything... -- Stef (remove caps, dashes and .invalid from e-mail address to reply by mail) Young men, hear an old man to whom old men hearkened when he was young. -- Augustus Caesar