Using assembly instructions and internal oscillator LFINTOSC...

This is actually  a sequel  to the previous  example,  but deals  with a bit more  complicated problem...  The idea is to make  LED diodes  on the port B blink slowly.  It can be done by setting large value for delay parameter in the Delay function. But there is also another, more efficient  manner to make this happen.  You remember  that this microcontroller  has built-in oscillator  LFINTOSC  which operates  at the frequency  of 31kHz? Now, it’s time to ‘give it a chance’.

The  program  starts  with  the do-while loop  and  remains  there  for  20  cycles.  After  each iteration,  100mS delay is provided,  which is reflected  as relatively  fast LED blinking of the port  B.  When  the  program  exits  this  loop,  the  microcontroller  starts  using  the  LFINTOSC oscillator as a clock signal source. The LED blinking is considerably  slower now even though the program executes the same do-whileloop with 10 times shorter delay.

For the purpose of making some potentionally dangerous situation more obvious here, control bits are activated by assembly instructions. Simply put, when entering or exiting the assembly instruction  in the program,  the compiler  doesn’t  save data on currently  active  RAM bank, which means that in this program section, bank selection depends on the SFR registers in use. When switching back to the program section written in C, the control bits RP0 and RP1 must return the state they had before ‘assembly language adventure’. In this program, the problem is solved by using the saveBank auxiliary variable which saves the state of these two bits.



You have noticed that the clock signal source is changed ‘on the fly’. If you want to make sure   of   it,   remove   quartz   crystal   prior   to   switchin the   microcontroller    on.   The microcontroller  will not start to operate  because  the Config Word loaded with the program requires the use of crystal on switching on. If you remove the crystal later during operation, nothing will happen, it will not affect the microcontroller at all.

0 komentar: