Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2024, 03:39:37 15:39


Login with username, password and session length


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

Posts: 709

Thank You
-Given: 1828
-Receive: 2885


Sow The Seeds of Love


« on: September 21, 2013, 10:21:18 10: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, 10:37:51 10:37 by sadman » Logged
Catcatcat
Senior Member
****
Online Online

Posts: 432

Thank You
-Given: 284
-Receive: 1647



WWW
« Reply #1 on: September 21, 2013, 03:53:18 15: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, 03:50:32 03: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
Hero Member
*****
Offline Offline

Posts: 709

Thank You
-Given: 1828
-Receive: 2885


Sow The Seeds of Love


« Reply #3 on: September 23, 2013, 05:18:09 05: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, 05:59:21 05: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
Junior Member
**
Offline Offline

Posts: 43

Thank You
-Given: 13
-Receive: 27


« Reply #5 on: September 23, 2013, 06:12:46 06: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
Hero Member
*****
Offline Offline

Posts: 709

Thank You
-Given: 1828
-Receive: 2885


Sow The Seeds of Love


« Reply #6 on: September 23, 2013, 07:20:03 07: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, 08:01:12 08: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
Hero Member
*****
Offline Offline

Posts: 709

Thank You
-Given: 1828
-Receive: 2885


Sow The Seeds of Love


« Reply #8 on: September 24, 2013, 05:35:04 05: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