Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: latch.h
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- /* Led Port (on/off) */
- #define LED_P0 P1OUT_bit.P0 /* Led Red */
- #define LED_P1 P1OUT_bit.P1 /* Led Green */
- /* Default values */
- #define NAND '&'
- #define NOR '|'
- /* NAND Port */
- #define NAND_SET ~(args->set & 0x0)
- #define NAND_RESET ~(args->reset & 0x0)
- /* NOR Port */
- #define NOR_SET ~(args->set | 0x1)
- #define NOR_RESET ~(args->reset | 0x1)
- typedef unsigned char led;
- typedef unsigned char dir;
- typedef signed char latch_input;
- typedef signed char latch_output;
- typedef struct logic device;
- struct logic
- {
- char logic_port; /* Logic Name */
- latch_input set, reset; /* Latch Input */
- latch_output q, q_; /* Latch Output */
- };
- //------------------------------------
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: functions.h
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- #include <io430.h>
- #include <stdlib.h>
- #include "latch.h"
- /* [ '&' to NAND ] / [ '|' to NOR ] */
- #define __CIRCUIT NOR
- /* Define what LED's do you working. ( OFF: 0 / Red: 1 / Green: 2 / Both: 3) */
- #define __TOGGLE_LED 3
- void call(void);
- void delay(void);
- void push_button_modules(void);
- dir get_toggle_led(void);
- static led __set_latch(device *args);
- static led __reset_latch(device *args);
- static void __start_port(device *args);
- //------------------------------------
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: functions.c
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- #include "functions.h"
- void call(void)
- {
- device *port = malloc(sizeof(device));
- if (port == NULL) {
- /* Memory could not be allocated */
- free(port); /* Allocated Memory is Free */
- } else { /* Allocation succeeded. Do something. */
- __start_port(port); /* The pointed-to-data must not be used again. */
- }
- #if (__TOGGLE_LED == 1) // Red.
- if (LED_P0 == 0x1)
- LED_P0 = __reset_latch(port); //P1OUT_bit.P0 = 0x00;
- else
- LED_P0 = __set_latch(port); //P1OUT_bit.P0 = 0x01;
- #elif (__TOGGLE_LED == 2) // Green.
- if (LED_P1 == 0x1)
- LED_P1 = __reset_latch(port); //P1OUT_bit.P0 = 0x00;
- else
- LED_P1 = __set_latch(port); //P1OUT_bit.P0 = 0x01;
- #else // Both LED's
- if (LED_P0 == 0x1 & LED_P1 == 0x1){
- LED_P0 = __reset_latch(port); //P1OUT_bit.P0 = 0x01;
- LED_P1 = __reset_latch(port); //P1OUT_bit.P1 = 0x01;
- } else {
- LED_P0 = __set_latch(port); //P1OUT_bit.P0 = 0x01;
- LED_P1 = __set_latch(port); //P1OUT_bit.P1 = 0x01;
- }
- #endif
- free(port); /* Allocated memory is Free */
- }
- inline void delay(void)
- {
- asm(" mov #0Ah, R14 "); // Load loop counter
- asm(" mov #0FFh, R15 "); // Load loop counter
- asm(" dec R15 "); // Decrements the R15 register.
- asm(" jnz $-2 "); // Back 2 positions on the memory.
- asm(" dec R14 "); // Decrements the R14 register.
- asm(" jnz $-4 "); // Back 4 positions on the memory.
- }
- void push_button_modules(void)
- {
- /* Put P2 port how input (Push Button) */
- P1DIR_bit.P2 = 0x0;
- /* Enable the internal resistor of
- * the button */
- P1REN |= 0x04;
- /* Enable interruption on P1.2 */
- P1IE |= 0x04;
- __bis_SR_register(GIE); /* Interrupção Global */
- }
- /* This Return Dir based on the Define __TOGGLE_LED*/
- dir get_toggle_led(void)
- {
- /* Set LED Dir (input/output) */
- if (__TOGGLE_LED == 3)
- return 0x03;
- else if (__TOGGLE_LED == 1 || __TOGGLE_LED == 2)
- return (__TOGGLE_LED == 1) ? 0x01 : 0x02; /* Toggle only one LED (RED/GREEN */
- else
- return NULL; /* Turn's Power OFF */
- }
- /* This function was created, which objective is set a LATCH. */
- static led __set_latch(device *args)
- {
- /* Set LATCH with the NAND logic circuit in the bitwise mode */
- #if (__CIRCUIT == NAND)
- args->set = 0x0;
- args->reset = ~(args->set);
- args->q = NAND_SET;
- args->q_ = ~(args->q);
- return (args->q); // latch out
- /* Set LATCH with the NOR logic circuit in the bitwise mode */
- #else
- args->set = 0x0;
- args->reset = ~(args->set);
- args->q_ = NOR_SET;
- args->q = ~(args->q_);
- return (args->q); // latch out
- #endif
- }
- /* This function was created, which objective is set the LATCH. */
- static led __reset_latch(device *args)
- {
- /* Reset LATCH with the NAND logic circuit in the bitwise mode */
- #if (__CIRCUIT == NAND)
- args->reset = 0x0;
- args->set = ~(args->reset);
- args->q_ = NAND_RESET;
- args->q = ~(args->q_);
- return args->q; // latch out
- /* Reset LATCH with NOR logic circuit in the bitwise mode */
- #else
- args->reset = 0x0;
- args->set = ~(args->reset);
- args->q = NOR_RESET;
- args->q_ = ~(args->q);
- return args->q; // latch out
- #endif
- }
- static void __start_port(device *args)
- {
- /* Start up initial values of the NAND port.*/
- #if (__CIRCUIT == NAND)
- args->logic_port = NAND;
- /* Latch Input */
- args->set = 0x1;
- args->reset = 0x1;
- /* Latch Output */
- args->q = 0x00;
- args->q_ = ~args->q;
- /* Start up initial values of the NOR port.*/
- #elif (__CIRCUIT == NOR)
- args->logic_port = NOR;
- /* Latch Input */
- args->set = 0x0;
- args->reset = 0x0;
- /* Latch Output */
- args->q = 0x00;
- args->q_ = ~args->q;
- #else
- #error (ERROR 0x00): "Please, put a correct logic circuit in the 'define' __CIRCUIT."
- #endif
- }
- //------------------------------------
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: interrupt.h
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- #define CP_PORT1_VECTOR (2 * 2u) /* 0xFFE4 Port 1 */
- #define HIBERNATE (0x00)
- #define POWER ( WDT_ADLY_1_9 )
- #define BOARD_ON 0x1;
- #define BOARD_OFF 0x0;
- typedef unsigned char current;
- extern unsigned char get_toggle_led();
- #pragma vector = CP_PORT1_VECTOR
- __interrupt void Port_1 (void);
- //------------------------------------
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: interrupt.c
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- #include "interrupt.h"
- #include <io430.h>
- #pragma vector = CP_PORT1_VECTOR
- __interrupt void Port_1 (void)
- {
- static current board_status = BOARD_ON;
- P1IFG &= ~0x04; /* Clean the register flag of interrupt */
- if(board_status) {
- P1DIR &= HIBERNATE;
- board_status = BOARD_OFF;
- }
- else {
- P1DIR = get_toggle_led();
- board_status = BOARD_ON;
- }
- }
- //------------------------------------
- /* Developed by Utroz & Kaddoush
- * Access: http://www.oakcoders.com
- * File: main.c
- *
- * printk(KERN_DEBUG "Dennis Ritchie(d.m.r) died. Rest in peace.");
- */
- #include "io430x22x4.h"
- #include "interrupt.h"
- extern void call(void);
- extern void delay(void);
- extern unsigned char get_toggle_led();
- extern void push_button_modules(void);
- int main(void)
- {
- WDTCTL = ( POWER ); /* Disables the watch dog timer */
- P1DIR = get_toggle_led();
- push_button_modules(); /* Initializes push button modules. */
- while(1){
- call();
- delay();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement