Content originally posted in LPCWare by teslabox on Sun Apr 27 08:22:09 MST 2014 Hi everyone!
I need to do remonte control driver (using RC-5 code). First I wrote a C code for my LPCXpresso LPC1769 (M3) because I have a lof of my own libraries for peripherals. The external interrupt (on the falling egde) on one pin and a timer inside it and reading pin state. Then colecting bits in MSB and LSB bytes and sengind them thru UART to the PC.
Next I do the same on LPC1114 - the smaller version (M0) of ARM uC but given values are different than at LPC1769.
// main programm
int main (void)
{
Timer32b_0_Init ();// Set clock to the Timer 32-bit No. 0
UART_Init (115200);// Set UART bitrate as 115200 bps
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
LPC_GPIO0->DIR|= (1<<1);
LPC_GPIO0->DATA|= (1<<1);
LPC_GPIO0->DIR &=~(1<<4);// PIO 0.4 as input
LPC_GPIO0->DATA |= (1<<4);// PIO 0.4 with pull-up
LPC_GPIO0->IS &=~(1<<4);// Interrupt sensitive on edge change (not on level)
LPC_GPIO0->IBE &=~(1<<4);// Interrupt on pin PIO 0.4 is controlled through register GPIO0IEV
LPC_GPIO0->IEV&=~(1<<4);// falling egde on pin PIO 0.4 triggers an interrupt
LPC_GPIO0->IE |= (1<<4);// GPIO at PIO 0.4 Interrupt Enable
NVIC_EnableIRQ (EINT0_IRQn);// 31 PIO_0 GPIO interrupt status of port 0
for (;;)
{
Timer32b_0_ms (500);
LPC_GPIO0->DATA^= (1<<1);// toggle the LED on pin PIO 0.1
}
return (0);
}
void Timer32b_0_Init (void)
{
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
}
void Timer32b_0_us (uint32_t Microseconds)
{
LPC_TMR32B0->TCR = 0x02;/* reset timer */
LPC_TMR32B0->PR = 0x00;/* set prescaler to zero */
LPC_TMR32B0->MR0 = Microseconds * ((SystemCoreClock/(LPC_TMR32B0->PR+1))/1000000);
LPC_TMR32B0->IR = 0xff;/* reset all interrrupts */
LPC_TMR32B0->MCR = 0x04;/* stop timer on match */
LPC_TMR32B0->TCR = 0x01;/* start timer */
/* wait until delay time has elapsed */
while (LPC_TMR32B0->TCR & 0x01);
}
void PIOINT0_IRQHandler (void)
{
uint8_t NumberOfBit = 0;
uint16_t RC5_Byte = 0;
uint8_t MSB, LSB = 0;
if (LPC_GPIO0->MIS & (1<<4))// If set the interrupt at PIO 0.4
{
Timer32b_0_us (444);
for (NumberOfBit = 0; NumberOfBit <= 13; NumberOfBit++)
{
RC5_Byte |= ((LPC_GPIO0->DATA & (1<<4)) >> NumberOfBit);
Timer32b_0_us (889);
}
MSB = (RC5_Byte & 0xFF00) >> 8;
LSB = (RC5_Byte & 0x00FF) >> 0;
LPC_GPIO0->IC |= (1<<4);// Clear interrupt at PIO 0.4
asm ("nop");
asm ("nop");
UART_SendByte (MSB);
UART_SendByte (LSB);
}
return;
}
In both cases I get the toogle bit and 2 bytes... so it looks almost OK but the values are different. My system core clock for LPC 1114 is 48 MHz so the Timer calculation for microseconds delay look also OK.
I don't know what's wrong with this. I'll be very grateful for help in this case ;). (If any data or information is missing I will write it down if you need.)
Content originally posted in LPCWare by R2D2 on Sun Apr 27 09:03:26 MST 2014 Quote: teslabox I don't know what's wrong with this. I'll be very grateful for help in this case ;).
With delays and (slow) UART function calls in ISR you are not really asking for help, aren't you?
0
件の賞賛
返信
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "このコンテンツはlilicon-trans-textからAI支援ツールを使って翻訳されました。".replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='原文を見る';
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='原文を見る';
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "lilicon-trans.your.convenience";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("alt", "翻訳アイコン");
// tr_fTag.setAttribute("title", "翻訳アイコンの免責事項");
tr_fTag.setAttribute("src", "/html/assets/translate-icon.svg");
tr_para.appendChild(tr_fTag);
var container = document.createElement('span');
container.innerHTML = tr_text;
//var tr_textNode = document.createTextNode(container);
tr_para.appendChild(container);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-message-body-content").previousElementSibling != null && rootElement.querySelector(".lia-message-body-content").previousElementSibling.getAttributeNames().includes("data-generation-timestamp")){
rootElement.querySelector(".lia-message-body-content").previousElementSibling.remove()
}
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-reply-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-reply-message")){
rootElement.querySelector(".lia-quilt-idea-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector('.lia-quilt-occasion-message')){
rootElement.querySelector('.lia-quilt-occasion-message .lia-message-body').insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
/*if(mszList_l.length <= 0){
setTimeout(()=>{
var mszListl = [];
angular.forEach(document.querySelectorAll("[class*='lia-js-data-messageUid']"), function(element) {
var mszId = element.getAttribute("data-lia-message-uid");
if (mszId != null) {
mszListl.push(mszId);
}
});
var mszListid = mszListl;
console.log("mszListl:",mszListl);
},2000)
}else{
var mszListid = mszList_l;
}*/
console.log("mszList_l:",mszList_l.length);
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '538679' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = "+"'lingo-body-"+value+"'"+"]";
lingoRSExp = "//lingo-sub[@id = "+"'lingo-sub-"+value+"'"+"]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i=0;i 0){
angular.forEach(document.querySelectorAll(".PageTitle"), function(subEle) {
subEle.textContent = sub_L;
});
}
}
}
// Label translation
try{
var labelEle = document.querySelector("#labelsForMessage");
if(!labelEle){
labelEle = document.querySelector(".LabelsList");
}
if(labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var labelsLength = document.querySelector(".LabelsList").querySelectorAll(".label").length;
var labelSnapshotLength = lingoLXML.snapshotLength;
if (labelsLength == labelSnapshotLength){
for (var k = 0; k < lingoLXML.snapshotLength; k++) {
//trLabels.push(lingoLXML.snapshotItem(i).textContent);
if (k != 0) {
//trLabelsHtml = trLabelsHtml + '