hi all,
i'm working with easy VR stamp kit. i want to start with the simplest application that is i want to push a buttun and drive an LED. but i can't set ports as inputs and outputs. how can i control ports to be inputs or outputs? i tried to use commands like p2ctla or so. but i coludn't do. can you help me pls?
thanks.
adjust port
example from directory \RSC4X-mikroC\Example\Led_Blinking.c
you can see register from datasheet 80-0206.pdf (rsc4128 datasheet)
if you want to use port to input, you will set pXctla, pXctlb as input
and read data from register pXin (p0in, p1in, p2in)
please tell me if you know how to declare or define each bit as another name
some thing like this,
I dont know how can write above code in MikroC
or It can not declare single bit, or It have some trick to declare
you can see register from datasheet 80-0206.pdf (rsc4128 datasheet)
Code: Select all
#include <rsc4128.h>
void Delay_ms(unsigned int time_ms);
void main() {
//--- init rscxxx - all pins digital, all outputs
//see analog comparator page 33,
//and see figure in page 34 cmpCtl bit[2:0] = 0x07
//0x07 = non use analog comparator
cmpCtl |= 0x07;
//see General Purpose I/O page 12
p0ctla = 255; //see port pin function table in page 13
p0ctlb = 255; //p0ctla and p0ctlb = 255, mean all bit = output
p1ctla = 255;
p1ctlb = 255;
p2ctla = 255;
p2ctlb = 255;
//register for send output to port
p0out = 0; //port0 led off
p1out = 0; //port1 led off
while (1) {
p2out = 0; //port2 led off
p0out = 255; //port0 led on
Delay_ms(200);
p0out = 0; //port0 led off
p1out = 255; //port1 led on
Delay_ms(200);
p1out = 0; //port1 led off
p2out = 255; //port2 led on
Delay_ms(200);
}
}//~!
and read data from register pXin (p0in, p1in, p2in)
please tell me if you know how to declare or define each bit as another name
some thing like this,
Code: Select all
declare... LED p1.0 <--- I need to use LED as bit 1.0
declare... BUTTON1 p1.2 <--- I need to use input BUTTON1 as bit 1.2
LED = 1; <--- I need to set p1.0
LED = 0; <--- I need to clear p1.0
or It can not declare single bit, or It have some trick to declare
-
- Posts: 10
- Joined: 18 Jun 2006 16:34
this is the demo io header file for Sensory demo board. Ports anmd input outputs are defined using #define:
may be this helps.[/quote]//
// File : demo_io.h
// Purpose : Definitions for the Demo/Eval Board
// Project : FC Samples
// Compiler : Phyton
//
// Copyright (c) 2003-2005 by Sensory Inc., All Rights Reserved.
//
//-----------------------------------------------------------------------------
// 02-mar-05 pk Added LED Toggle definitions
// 07-feb-05 pk Added LED definitions
//-----------------------------------------------------------------------------
#ifndef __DEMO_IO_H
#define __DEMO_IO_H
#define BTN_reg p1in
#define BTN_PORT 1
#define BTN_A 0x10
#define BTN_B 0x20
#define BTN_C 0x40
#define BTN_D 0x80
#define BTN_ALL 0xF0
#define ButtonAPressed (!(BTN_reg & BTN_A))
#define ButtonBPressed (!(BTN_reg & BTN_B))
#define ButtonCPressed (!(BTN_reg & BTN_C))
#define ButtonDPressed (!(BTN_reg & BTN_D))
#define ButtonPressed ((BTN_reg & BTN_ALL) != BTN_ALL)
// Definitions and macros for LED control
// NOTE: API functions exist for these (e.g. _GreenOn)
// which use the definitions in config.mca. Sometimes
// using these functions causes compiler warnings,
// (since the functions are also used by some technology
// library code) so these macros can be used to avoid the warnings.
#define LED_reg p1out
#define LED_GREEN 0x01
#define LED_YELLOW 0x02
#define LED_YELLOW2 0x04
#define LED_RED 0x08
#define LED_ALL 0x0F
#define GreenOn LED_reg |= LED_GREEN
#define GreenOff LED_reg &= ~LED_GREEN
#define GreenToggle LED_reg ^= LED_GREEN
#define YellowOn LED_reg |= LED_YELLOW
#define YellowOff LED_reg &= ~LED_YELLOW
#define YellowToggle LED_reg ^= LED_YELLOW
#define Yellow2On LED_reg |= LED_YELLOW2
#define Yellow2Off LED_reg &= ~LED_YELLOW2
#define Yellow2Toggle LED_reg ^= LED_YELLOW2
#define RedOn LED_reg |= LED_RED
#define RedOff LED_reg &= ~LED_RED
#define RedToggle LED_reg ^= LED_RED
#define ColLedsOn LED_reg |= LED_ALL
#define CollLedsOff LED_reg &= ~LED_ALL
#endif