ELECTRONICS AND MATHEMATICS

COME ON MEET A PERSON WHO DIFFERS


A simple counter in Mikrobasic

20.08.2008 A simple counter
It was in the evening as I took the code from Lez (
http://lez.briddon.googlepages.com/lcdonql200with16f877a) and I added to his code a simple counter.
I was the whole day down and I thought that I was doing all things for naught. But as it was functionalizin I decided to publish the counter in the web.

and here the code :

program LCD_COUNTER

'
'
'
'
' QL200 and LCD1602 Demo in Mikrobasic using 16f877a
'
'
'
'
' Do not use LCD_INIT in mikrobasic on ql200, will not work!
'
' Remember to set the right PIC type and Crystal frequency
' and fuse settings!
'
' Also set jumpers on S14 to 2,3,4,11,12,13,14, others can be removed and stored
' set s1 and s4,s5,s6 to 'all off'
'

dim i as longint
    ch as byte

main:

                ' switch off the analog inputs on PIC
  ADCON0 = 0
  ADCON1 = 0x0F


                ' Set all PIC ports to output
  trisa=0
  trisb=0
  trisc=0
  trisd=0



  portb=255   ' Set all portb high for one second, just to show sign of life!
  porta=255
  portc=255
  portc=255
  delay_ms(1000)
  portd=0     '   Also useful as if not high for 1 second, you have wrong crystal / config fuses on cpu_div
  portc=0
  portb=0
  porta=0
  delay_ms(1000)


  ' init lcd on board using lcd_config.
  ' do not use lcd_init on ql200
  ' for a 877a use
  ' lcd_config(portd,7,6,5,4,porta,1,2,3)

  lcd_config(portd,7,6,5,4,porta,1,2,3)  ' use this for 877a

  i = 0
  forever:   ' we will use a simple GOTO to creat an infinate loop


  lcd_cmd( LCD_CLEAR)      ' LCD "clear display"

  delay_ms(1000)           ' wait one second

  lcd_out(1,1,"A SIMPLE COUNTER")  ' show 'working...' on LCD, 1st row, 1st column
  lcd_out(2,1,"20.8.2008")
 
  i = i + 1 ' and here the counter :
 
  ch    = (i div 1000) mod 10 ' the counter counts up from 0 until 9999
  Lcd_Chr(2,11,ch+48)
  ch    = (i div 100) mod 10
  Lcd_Chr(2,12,ch+48)
  ch    = (i div 10) mod 10
  Lcd_Chr(2,13,48+ch)
  ch    = i mod 10
  Lcd_Chr(2,14,48+ch)


  delay_ms(2000)           ' wait two seconds

  lcd_cmd( LCD_CLEAR)      ' LCD "clear display"

  lcd_out(1,1,"Pavle Djukanovic") ' show 'working..' on LCD, 1st row, 1st column

  lcd_out(2,1,"+4971466941") ' show 'working..' on LCD, 2nd row, 1st column

  delay_ms(1000)           ' wait one second


goto forever

end.

Create a free website at Webs.com