Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 10, 2016, 11:17:41 23:17


Login with username, password and session length


Pages: [1]
Print
Author Topic: 8 bit baniary counter  (Read 1415 times)
0 Members and 1 Guest are viewing this topic.
sadman
Active Member
***
Offline Offline

Posts: 231

Thank You
-Given: 718
-Receive: 688



« on: September 21, 2013, 11:21:18 11:21 »

hi

i have ported a c code to basic for 8 bit binary counter but my code is not working as original one can some one help me to fix this i have uploaded both original and ported code here with simulation file

regards
sadman



« Last Edit: September 21, 2013, 11:37:51 11:37 by sadman » Logged
Catcatcat
Active Member
***
 Warned
Offline Offline

Posts: 117

Thank You
-Given: 89
-Receive: 258



WWW
« Reply #1 on: September 21, 2013, 04:53:18 16:53 »

Of course will not work, read here http://catcatcat.d-lan.dp.ua/en/skachat/primeryi-postroeniya-koda-programm-dlya-pic-kontrollerov/tsifrovoy-vvod-dannyih/ if Google release translation understand, there is an example.
Logged
robotai
Junior Member
**
Offline Offline

Posts: 60

Thank You
-Given: 27
-Receive: 23


« Reply #2 on: September 23, 2013, 04:50:32 04:50 »

In C code, we use "{..}"  to form program block.

In Basic code, "If" should has related "End If" to form program control block. Obviously you missed it.
Logged
sadman
Active Member
***
Offline Offline

Posts: 231

Thank You
-Given: 718
-Receive: 688



« Reply #3 on: September 23, 2013, 06:18:09 06:18 »

In C code, we use "{..}"  to form program block.

In Basic code, "If" should has related "End If" to form program control block. Obviously you missed it.

can you please provide a example
Logged
robotai
Junior Member
**
Offline Offline

Posts: 60

Thank You
-Given: 27
-Receive: 23


« Reply #4 on: September 23, 2013, 06:59:21 06:59 »

Well, not sure what example you want? If you don't understand the syntax, maybe you need to study the BASIC language from the beginning.

For part of your code, it should looks like
Code:
If up=1 Then
  bcount=bcount+1
  DelayMS 100
  If bcount=0 Then bcount=255
End If
If dn=1 Then
  bcount=bcount-1
  DelayMS 100
  If bcount=255 Then bcount=0
End If

You didn't port the debounce part from C code exactly. Maybe you are using your way.
Logged
ero
Newbie
*
Offline Offline

Posts: 23

Thank You
-Given: 1
-Receive: 16


« Reply #5 on: September 23, 2013, 07:12:46 07:12 »

Here is the working code;
Code:
Device = 16F628
Xtal = 4
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, BODEN_OFF, LVP_OFF, CP_OFF, MCLRE_OFF ;On-chip RC-oscillator
All_Digital TRUE

CMCON=7

TRISB=0
TRISA=%00000011
Symbol up=PORTA.0
Symbol dn=PORTA.1
 
Dim bcount As Byte

bcount=0
PORTB=0
DelayMS 300

start:
If up=1 Then
bcount=bcount+1
If bcount=0 Then  bcount=255
PORTB=bcount
WHILE UP=1:WEND
DelayMS 50
endif

If dn=1 Then
 bcount=bcount-1
 If bcount=255 Then bcount=0
 PORTB=bcount
 while dn=1:wend
DelayMS 50
endif

GoTo start
End

ero
Logged
sadman
Active Member
***
Offline Offline

Posts: 231

Thank You
-Given: 718
-Receive: 688



« Reply #6 on: September 23, 2013, 08:20:03 08:20 »

Well, not sure what example you want? If you don't understand the syntax, maybe you need to study the BASIC language from the beginning.

For part of your code, it should looks like
Code:
If up=1 Then
  bcount=bcount+1
  DelayMS 100
  If bcount=0 Then bcount=255
End If
If dn=1 Then
  bcount=bcount-1
  DelayMS 100
  If bcount=255 Then bcount=0
End If

You didn't port the debounce part from C code exactly. Maybe you are using your way.


how i can add debounce part
Logged
robotai
Junior Member
**
Offline Offline

Posts: 60

Thank You
-Given: 27
-Receive: 23


« Reply #7 on: September 23, 2013, 09:01:12 09:01 »

I think ero has ported it for you on previous reply.

For better mechanism, you can refer to
http://www.microchip.com/forums/m265696.aspx
This is much like what I have usually used.
Logged
sadman
Active Member
***
Offline Offline

Posts: 231

Thank You
-Given: 718
-Receive: 688



« Reply #8 on: September 24, 2013, 06:35:04 06:35 »

thank to all friends for the support finally i get it working as required
 
sadman
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC